Afamee
Afamee

Reputation: 5320

Difficulty executing shell script with directory reference

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

Upvotes: 1

Views: 181

Answers (3)

Roman Cheplyaka
Roman Cheplyaka

Reputation: 38758

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.

Upvotes: 1

Nate
Nate

Reputation: 19472

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.

Upvotes: 1

Jonathan
Jonathan

Reputation: 13624

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.

Upvotes: 0

Related Questions