On Mon, Jul 02, 2001 at 04:06:47PM -0300, Silvio Luis Leite Santana wrote:
> It seems the backtick operator calls the shell, otherwise
> it wouldn't be able to redirect output to file saida.

Backticks aren't the only thing that uses the shell, nor do they always use
the shell.  A simple `pwd` won't use the shell, it's only when shell
metacharacters are introduced that it's run through the shell.

Some other operators that use the shell: string form of system, with shell
metacharacters; string form of exec, with shell metacharacters; glob and <*>
(prior to perl 5.6); string form of open, with shell metacharacters.

 
> 1) What shell does it call?

The shell deemed most appropriate at compile-time.  Usually it's simply
/bin/sh.  This will tell you what shell, exactly:

    perl -MConfig -wle 'print $Config{"sh"};

so will this, on a system with strace:

    strace -f -eexecve perl -wle 'print `pwd 2>&1`'


> 2) What about calling the Perl intrerpreter, not in a shell,
> but somewhere else on the system, like being the program
> to be executed as soon as a user log in, for example, the
> "shell entry" in /etc/passwd? (we have no shell running till
> that moment)

It wouldn't make for very portable code if you could call any shell you
liked.  At the very least the shell has to understand how to properly expand
globs, as older versions of perl use the shell to expand the pattern in <*>
and glob("*").  For greater portability between Perl scripts the shell
should understand basic redirection, >, 2>, 2>&1, etc., as well as
the ability to background with &.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--
  • backticks Silvio Luis Leite Santana
    • Michael Fowler

Reply via email to