lists on 19 Nov 2007 17:42:16 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Perl backticks/system question


> On Mon, Nov 19, 2007 at 11:08:41AM -0500, lists@linuxnotes.net wrote:
>> Hi all,
>> I have a bash script that I need to run from within a Perl script and
capture the output.  My script works fine until it hits a parentheses
in
>> an argument and then I get:
>>     sh: -c: line 0: syntax error near unexpected token `('
>> I understand that if there are arguments in backticks the command is sent
>> to the shell for interpretation, but if I run the command outside of my
Perl script it works fine so I am not sure where I am getting the error
from.  I have used quotemeta() to escape all the special characters.
>
> When you execute a command with backticks from within perl, you might
think that perl just uses whatever shell it was started from, but that's
not what happens.  Instead, perl uses the default shell it found when it
was being configured on your system.  Normally this is /bin/sh.  You can
see what your perl is using with the command
>
> % perl -MConfig -le 'print $Config{sh}'

    root@2[cgi-bin]# perl -MConfig -le 'print $Config{sh}'
    /bin/sh
    root@2[cgi-bin]#
>
> My guess is that /bin/sh is linked to bash (which gives the error
message you posted), while you're using some other shell (perhaps ksh?).
 On many shells (e.g. bash, zsh, and csh) parens are special characters
that do some sort of expansion, but on your shell they're not.  I can
think of several workarounds, but the solution you've found (quotemeta)
seems as easy as anything else.
>

    root@2[cgi-bin]# ls -al `which sh`
    lrwxrwxrwx 1 root root 4 Jul  6 12:59 /bin/sh -> bash

So it looks like I am using the same shell, but still getting the errors.


> Walt
> ___________________________________________________________________________
Philadelphia Linux Users Group         --
> http://www.phillylinux.org
> Announcements -
> http://lists.phillylinux.org/mailman/listinfo/plug-announce
> General Discussion  --
> http://lists.phillylinux.org/mailman/listinfo/plug
>




___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug