views:

41

answers:

3

Hey Guys,

I have a simple script

...
dir=`pwd`
echo $dir

cd ./selenium-grid-1.0.8/

CMD="ant -Dport=$1 -Dhost=$2 -DhubURL=http://172.16.1.137:4444 -Denvironment="$3"-DseleniumArgs="-firefoxProfileTemplate C:/software/rc_user_ffprofile -multiWindow" launch-remote-control"
echo $CMD
$CMD 2>&1

#End

Whenever i run this command, i get: ./register_rc.sh: line 16: C:/software/rc_user_ffprofile: is a directory

this directory has to be an argument to the -firefoxProfileTemplate option. How do i include that in this string without it baffing??

help

thnx

A: 

Looks like you're mixing your quotes up. Take a look at the syntax highlighting that StackOverflow did for you.

I recommend generating the CMD variable in multiple steps, and make sure you \-escape your quotes.

Jonathan
+1  A: 

I believe your command should read:

CMD="ant -Dport=$1 -Dhost=$2 -DhubURL=http://172.16.1.137:4444 -Denvironment=\"$3\"-DseleniumArgs=\"-firefoxProfileTemplate C:/software/rc_user_ffprofile -multiWindow\" launch-remote-control"

The backslashes are used to "escape" the quotation marks.

Nate
thanks nate. appreciate your answer
Afamee
+1  A: 

The answers here telling to escape your quotes are wrong. That will pass those quotes directly to ant, I doubt that's what you want.

What's the reason to store the command in a variable? It's a very bad idea. Why can't you just write that command as is? If you want to achieve modularity or code reuse, then define a function.

If you want to display executed commands, use set -x.

Roman Cheplyaka
Excellent advice. See [BashFAQ/050](http://mywiki.wooledge.org/BashFAQ/050) for more info (applicable to ksh, etc., too).
Dennis Williamson