Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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/ld-linux.so). 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.

Links:

Alexander

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

In reply to Re^2: Shebang behavior with perl by afoken
in thread Shebang behavior with perl by McKreeger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found