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


New Member
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!

# populate var0
read -r var0<<-EOF

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


# 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..


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


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.

Staff online

Members online