Hi peterbk,
It is not Perl which decides how to split the command line arguments, it is the shell. Which shell are you using? I'm not an expert on the intricacies of shell quoting, but from what I do know it can be a minefield of brittle/non-portable solutions.
I would recommend finding a different solution to passing arguments to your script, such as allowing your script to get options from a file in addition to accepting ones from the command line (I don't find that awkward). Also, note that Perl can access environment variables via the %ENV hash, but if those contain quotes, you will have to parse those yourself, such as with shellwords from Text::ParseWords, as Corion suggested.
Using a file to pass parameters gives you a lot of flexibility on formats, which all handle the quoting/escaping of values too (JSON, YAML, XML, any of the Config:: modules, etc.).
Here's a little bash trick I sometimes use for temporary files that get cleaned up when the script ends, you could use this to generate the file which holds the values:
# in your bash script TEMPFILE="`mktemp`" trap 'rm -f "$TEMPFILE"' EXIT echo "whatever" >$TEMPFILE # ...
Update: If your Perl script happens to be using Getopt::Long, note that it has the function GetOptionsFromString, and if you're using Getopt::Std, see my node here. Both of these solutions use shellwords from Text::ParseWords.
Hope this helps,
-- Hauke D
In reply to Re: passing parameters from shell script to perl program doesn't preserve spaces
by haukex
in thread passing parameters from shell script to perl program doesn't preserve spaces [solved]
by peterbk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |