Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: Shebang behavior with perl

by afoken (Chancellor)
on Mar 03, 2015 at 11:30 UTC ( #1118590=note: print w/replies, xml ) Need Help??

in reply to Re: Shebang behavior with perl
in thread Shebang behavior with perl

Unix-shell programs are designed to read the first line of any “command file,” looking therein for a #!shebang™ line. If they find one, they fork() the specified command, providing “the rest of the input-file” to the subprocess.

I doubt that. In modern unixes, the shell simply fork()s and then wait()s, and, in the child process, invokes exec(script,arguments). The kernel, not the shell, detects what kind of file is about to be executed, and runs the proper loader/interpreter. For dynamically linked ELF binaries, the proper loader name is embedded in the ELF file (something like /lib/ For other file formats, a similar logic is used. For some file formats, a hard-coded or configurable helper program is invoked. For scripts that start with #!, the interpreter is the first "word" (block of non-whitespace characters) after #!. It may have an optional argument (everything up to end of line).

Shells usually have some fallback code that handles a failing exec() for a text file, as required by POSIX.



Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2023-11-30 04:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found