Reputation: 7
I'm a perl
noob here and was wanting to run this from the command line of my unix machine.
./myprog.pl $str1 str2
Where I need to replace str2
with str1
. Trouble is that I don't know how to escape from the $
in the str1
argument. I tried looking on here and on other websites but I couldnt find anything. Any help would be greatly appreciated!
Upvotes: 1
Views: 301
Reputation: 386706
What shell? Is that the bourne-shell or a derivative, then both of the following will pass $str1
and str2
to the program.
./myprog.pl '$str1' str2
./myprog.pl \$str1 str2
But you talk of "replacing". Is the first arg suppose to be a regex pattern that matches $str1
? If so, then you can use either of the following:
./myprog.pl '\$str1' str2
./myprog.pl \\\$str1 str2
This escapes $
for the regex engine (by adding a \
), then escapes the \
and $
for the shell (by adding quotes or extra \
s).
Upvotes: 1