I am trying to create a bash file which calls a program that expects a parameter to submitted between two double quotes.

Take a look at my file content.

echo ./yowsup/yowsup-cli demos --s $1 \"$2\" -c yowsup/config &
./yowsup/yowsup-cli demos --s $1 \"$2\" -c yowsup/config &

The echo part prints exactly the command I need, but when I comes to execute it (next line), I am messing it up.

How can I get this fixed?


This is how I need to call it:

./yowsup/yowsup-cli demos --s 9999999999 "my parameter" -c yowsup/config

Echo result:

./yowsup/yowsup-cli demos --s 9999999999 "my parameter" -c yowsup/config

Call result:

demos: error: unrecognized arguments: parameter

Copying and pasting echo results:

INFO:yowsup.demos.sendclient.layer:Message sent
  • 1
    What's in $2? What happens if you just double quote both the variables? --s "$1" "$2" -c
    – choroba
    Mar 22, 2015 at 12:35
  • See my comments
    – user101903
    Mar 22, 2015 at 12:52

2 Answers 2


You need to escape the quotes in the echo command to see them in the output, but you shouldn't escape them in the actual command:

echo ./yowsup/yowsup-cli demos --s $1 \"$2\" -c yowsup/config &
./yowsup/yowsup-cli demos --s $1 "$2" -c yowsup/config &

The quotes are used in the actual command to prevent splitting of $2 - which contains multiple words.

  • 3
    @user1688175 by the way, if you do want to see what commands get executed, use set -x instead of complicated echo commands.
    – muru
    Mar 22, 2015 at 13:11

I (nearly) always quote everything to "echo", so I would do the above like:

echo "./yowsup/yowsup-cli demos --s $1 \"$2\" -c yowsup/config &"
./yowsup/yowsup-cli demos --s $1 "$2" -c yowsup/config &

The difference with @muru solution is, that there the original echo command is run "in the background" - here it's echoing to the screen in the foreground, but run as a background command. (@muru's also doesn't show the ampersand at the end of the command.)

  • At first it looked like you just copy-pasted @muru's answer and that might be why you get the downvotes. so I (hopefully) made the "As it stands" text less ambigious.
    – Anthon
    Jan 30, 2016 at 6:15
  • Thanks Anthon, your edit looks like a much better explanation. (An "echo" command without quotes always looks dangerous to me.)
    – wanpelaman
    Feb 1, 2016 at 9:54

You must log in to answer this question.