execute commands from .sh script don't work, wrong "space-signs"?

Nemesis

New Member
Credits
0
hi all!

I've been trying to get a .sh script to work the past days but I'm obviously not smart enough to grasp the concept, because it doesn't work.

the script is suppose to send a message via messenger, and the program messer the "solution"
but something isn't right, because it says
Logging in...
Invalid message - check your syntax

but then l when I check the output (see script bug check), the command is perfectly fine!

Bash:
#!/bin/sh
# populate var0
read -r var0<<-EOF
messer
EOF

# populate var1
read -r var1<<-EOF
 --command='m "Adam Larsson" testing
EOF
# populate var2
read -r var2<<-EOF
[email protected] ...

EOF
var4="'"

# Join Forces
var3="$var0 $var1 $var2 $var4"   
echo $var3>txt.txt # dumping result (bugcheck)
$var3  # Executing command
I've tried both bash and sh (#!/bin/bash & #!/bin/sh)

so when executing the command: ./script.sh testing testing
the var3 variable is set to: messer --command='m "Adam Larsson" testing testing '
and the end result is:

Logging in...
Invalid message - check your syntax


BUT! if I'm copying the var3 data, with a "normal copy text function" paste it into the terminal and press enter, it works flawless..
Logging in...

Sent message to Adam Larsson


so I'm wondering why?, if the var3 variable contains the correct command-string, why isn't it working when the script file tries to execute it..
 


rovf

New Member
Credits
0
$var does not undergo parsing for the quotes anymore; so you are calling the command messer with the 5 arguments

--command='m
"Adam
Larsson"
testing
testing


which does not make much sense.

One possibility would be to do

eval "$var3"

but this opens a huge security hole, because whoever feeds the input to the read commands, could inject arbitrary code to be executed.
 


Members online


Top