in reply to Re: Re: passing string to stdin on exec-command
in thread passing string to stdin on exec-command
The answer lies in the fact that the shell does concatenation by absense of whitespace. So, if we want to put O'Reilly inside quotes, we break the string into three parts: O, ' and Reilly. The first and last part will be surrounded by single quotes, the single quote will be surrounded by double quotes, and then we stick the three parts together, resulting in: 'O'"'"'Reilly'. This sounds complicated, but we can do this with a single substitution: s/'/'"'"'/g.
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; my $orig = $_; s/'/'"'"'/g; my $result = `echo '$_' | cat`; chomp $result; print STDERR "Mismatch [$orig] vs [$result]\n" unless $result eq $ +orig; } __DATA__ foo bar 'foo bar' foo'"'bar '''''''''''' ''''''''''' "foo'bar" "foo''bar" "foo'bar"" ' "'"
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Re: passing string to stdin on exec-command
by merlyn (Sage) on Nov 05, 2003 at 16:48 UTC |