EvanCarroll has asked for the wisdom of the Perl Monks concerning the following question:

How does perl manage backticks do they pass through the shell? or is it ... deeper than that ?

The question is really quite simple, how does this not work:
perl -e'print `for i in {1,2,3}; do echo $i; done;`'


But this does:
perl -e'print `ls | head -n 1`'


Evan Carroll
www.EvanCarroll.com

Replies are listed 'Best First'.
Re: Lets talk backticks
by davidrw (Prior) on May 31, 2006 at 01:48 UTC
    This works:
    perl -e'print `for i in {1,2,3}; do echo \$i; done;`'
    You have to escape the $ so it makes it to the shell .. quoting perlop (The 'I/O Operators' section): A string enclosed by backticks (grave accents) first undergoes double-quote interpolation.
Re: Lets talk backticks
by Fletch (Bishop) on May 31, 2006 at 12:43 UTC

    Checking perlop the very first sentence under the qx// operator is:

           qx/STRING/
           `STRING`
                   A string which is (possibly) interpolated and then executed as
                   a system command with "/bin/sh" or its equivalent.
    

    What part of executed as a system command with "/bin/sh" or its equivalent was unclear?