Now riddle me this... in the following scenario, I want to generate a quoted command-line argument via a shell command which then gets passed to a Perl script, like this:
script.pl `echo --string \"blah blah yup\"`
Trouble is, GetOptions ("string=s" => \$string)
sets string's value to
"blah
containing the initial double-quote character and breaking at the first whitespace. The echo command by itself outputs the parameter with a quoted string that looks peachy:
--string "blah blah yup"
and if I call script.pl --string "blah blah yup"
without the echo, the whitespace containing string gets set in the Perl script as expected.
I thought that maybe the backticks were the issue, but the same results ensue with these variants:
script.pl $(echo --string \"blah blah yup\")
script.pl $(echo "--string \"blah blah yup\"")
script.pl $(echo --string \"blah\ blah\ yup\")
script.pl $(echo '--string \"blah blah yup\"')
though that last example leads to string=\"blah
(containing the initial backslash and double quote character).
Seems like the output returned from a shell command's STDOUT is not being handled the same way by Perl's argument parsing machinery as a string that is typed into the command-line. This apparent lack of string fungibility is somewhat surprising, but probably owing to some aspect of bash I don't understand. (Btw, I tested this with Perl 5.24 on Darwin and 5.16 on Linux)