Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

perlscript as she-bang line

by saintmike (Vicar)
on Dec 28, 2004 at 22:52 UTC ( #417866=perlquestion: print w/replies, xml ) Need Help??

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

Fellow monks,

let's say there's a perl script /tmp/parse_me which has a she-bang line calling the perl interpreter and expects a file as an argument.

Now, when a script like

#!/tmp/parse_me some text
gets called from the command line, the bash shell will call another instance of bash and hand it some text, which of course throws an error:
./scriptname: line 3: some: command not found

However, if the above script gets called in the zsh shell, it correctly calls

/tmp/parse_me scriptname
and succeeds.

Does anyone know if there's a limitation in bash that only allows executables in the she-bang line, and prohibits using perl- and other scripts?

Replies are listed 'Best First'.
Re: perlscript as she-bang line
by simonflk (Pilgrim) on Dec 28, 2004 at 23:36 UTC
Re: perlscript as she-bang line
by ambrus (Abbot) on Dec 28, 2004 at 23:13 UTC

    The shebang line is handled by the kernel, not the shell. A script after the shebang line is not allowed.

    From the execve(2) manpage:

    execve() executes the program pointed to by filename. filename must be either a binary executable, or a script starting with a line of the form "#! interpreter [arg]". In the latter case, the interpreter must be a valid pathname for an executable which is not itself a script, which will be invoked as interpreter arg filename.
      That's what I thought as well, but that's obviously not the case, as the difference between zsh and bash shows.

        Ah, I didn't read your node carefully, and failed your comment about zsh.

        Well, it's zsh then. From info zsh "Command Execution":

        If execution fails because the file is not in executable format, and the file is not a directory, it is assumed to be a shell script. /bin/sh is spawned to execute it. If the program is a file beginning with `#!', the remainder of the first line specifies an interpreter for the program. The shell will execute the specified interpreter on operating systems that do not handle this executable format in the kernel.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://417866]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-05-18 07:12 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (68 votes). Check out past polls.