Reputation: 1321
Space ignorance issue, when passing perl script with option(space contained value) as argument.
use strict;
use Getopt::Long;
my $option;
GetOptions(
"myreg=s"=>\$option,
);
print "Option: $option\n";
I have a shell script and when I pass the perl script with option (space contained value) the script print only the option value before to the space.
/my/test/script.sh /my/testing/test.pl --myreg='Reg 1'
The above execution prints,
Option: Reg
What the issue? Please assist.
Upvotes: 1
Views: 138
Reputation: 386361
It's because of improper escaping performed by /my/test/script.sh
, something along the lines of doing $@
or exec $@
instead of "$@"
or exec "$@"
.
$ cat ./bad
#!/bin/sh
exec $@
$ ./bad ./test --myreg='Reg 1'
Option: Reg
$ cat ./good
#!/bin/sh
exec "$@"
$ ./good ./test --myreg='Reg 1'
Option: Reg 1
Upvotes: 3