in reply to Re: Running Entire Bash Script Inside Perl
in thread Running Entire Bash Script Inside Perl
That design requires advance knowledge of the script (to change $1 to the parameter). I don't know if that's a problem.
The implementation fails if $param contains two spaces in a row, a quote, etc due to improper encoding of strings. Fix:
sub to_sh_lit { my ($s) = @_; die if !utf8::downgrade($s, 1); # Expecting bytes. die if $s =~ /\x00/; # NUL can't be passed. $s =~ s/('+)/'"$1"'/g; return "'$s'"; } my $lit_param = to_sh_lit($param); print SH "echo $lit_param\n";
Update: Added code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Running Entire Bash Script Inside Perl
by graff (Chancellor) on Jun 19, 2009 at 23:48 UTC |