views:

437

answers:

2

I'm writing a Bash script in which I am running a perl script which requires flags that have double quotes in them. Running the script normally, you would run

$ perl script.pl -flag="something" -anotherflag="somethingelse"

In my script, I'm using variables in these flags, but would like to preserve the doublequotes, so I have something like:

variable=foo
perl script.pl -flag=\"something\" -anotherflag=\"$variable\"

when i run bash -x myscript.sh, I see that it adds single quotes around the entire flag, while maintaining the doublequotes, causing the perl script to error:

perl script.pl '-flag="something"' '-anotherflag="foo"'

I also tried evaling the whole thing (eval perl [...]), and it stripped out the doublequotes altogether. How can I have Bash run the script with the doublequotes intact?

A: 

You say...:

Running the script normally, you would run

$ perl script.pl -flag="something" -anotherflag="somethingelse"

...but then the shell running at the $ prompt would remove the ": perl's script would never see them (they'd just have played their role of preventing spaces, and special characters such as '>', '<', '|, etc, from being interpreted within them -- those spaces and/or special characters would just be passed on as part of the arg). With the values as you're giving them (no spaces, no specials), those double quotes are totally useless and it would do absolutely no difference to omit them.

Anyway, if that is indeed the effect you want, just do in your bash script:

perl script.pl -flag="something" -anotherflag="$variable"

(or, omit the double quotes -- it's absolutely indifferent around something, indifferent around $variable if as in your example it's just foo but not in all cases).

Alex Martelli
A: 

Well the basic question is, why do you want to preserve the double quotes into perl?

Gunstick