Oh Wise Monks,
A need recently arose to pipe an arbitrary (short) string into a shell command and get the results. I wanted to avoid open2, and thought: the biggest issue is that some malicious person might try to inject things like "$" and quote characters, etc. No problem: I can write something that converts my input string into something that the Unix command printf (or echo -e) will interpret into the correct string, which then gets piped to the command. But then it didn't work:
$cmd = "printf 'I\\x27ll'"; print $cmd . "\n"; print `$cmd` ."\n";
I am confused because the shell gives the result I want, but backticks (and open '-|') do not!
> printf 'I\x27ll'In reply to backslashes in shell commands by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |