develooper Front page | perl.perl5.porters | Postings from May 2006

Re: [perl #39011] system, exec etc unable to handle shell functions

Thread Next
Cai Qian
May 1, 2006 02:57
Re: [perl #39011] system, exec etc unable to handle shell functions
Message ID:

On 4/27/06, Dominic Dunlop via RT <> wrote:
> Thank you for your report, but this is not a bug.
> On 2006â€"04â€"27, at 11:56, Qian Cai (via RT) wrote:
> > go() { echo Hello; }; export -f go; perl -w <<< 'system("go");'
> >
> > - Not work; Can't exec "go": No such file or directory at - line 1.
> >
> > go() { echo Hello; }; export -f go; perl -w <<< 'system("ls; go");'
> >
> > - It works, as the first command in "system" is an external command.
> The difference is that, in the first example, perl sees no characters
> that are special to the shell in the argument to system(), and so
> tries to exec  go  directly. This fails because there is nothing of
> that name in the search path. In the second case, perl sees a
> semicolon, and so passes the system()'s argument to a shell to
> process, resulting in the function being found in the environment.
> You can make the first example work as you want by changing the
> argument to system to "go;", or by explicitly running a shell:
> perl -w <<<'system(qw(sh -c go))'
> For more information, see
> perldoc -f system
> --
> Dominic Dunlop

It seems better to have a same behavior as AWK, or even C, so there is
no need to  supply such  addition ; or sh -c.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About