Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

(OT) Re^3: The basics

by Hue-Bond (Priest)
on Jun 24, 2006 at 21:59 UTC ( #557403=note: print w/ replies, xml ) Need Help??


in reply to Re^2: The basics
in thread The basics

To the shell. [...] At least on unixish systems, there is always a shell involved in this process

The #! line, also called shebang, tells nothing to any shell. It's the kernel who interprets it. When the first two bytes of an executable file are #!, the kernel runs the command that follows them, with the parameters specified, and feeds it the whole file on its standard input:

$ cat > a #!/usr/bin/tail -n2 1 2 3 4 5 6 7 ^D $ chmod +x a $ ./a 6 7 $ strace ./a 2>&1 | grep -c sh 0

--
David Serrano


Comment on (OT) Re^3: The basics
Download Code
Replies are listed 'Best First'.
Re^4: The basics
by Tanktalus (Canon) on Jun 25, 2006 at 14:25 UTC

    I'm trying to figure out where you get the idea that the contents are passed to tail's stdin. It's not. The full path to the file (as given by the shell - full path if searched via PATH, relative path if PATH not used) is passed in.

    Compare the output of "strace ./a" and "strace /usr/bin/tail -n2 < a". The former has a call to "open" and all reading is done from filehandle 3. The latter doesn't call open, and all reading is done from filehandle 0.

      I'm trying to figure out where you get the idea that the contents are passed to tail's stdin.

      I guess I'll also have to. To my surprise, you're right.

      --
      David Serrano

Re^4: The basics (history)
by tye (Cardinal) on Jun 25, 2006 at 05:55 UTC

    Just FYI: That is only true for recent Unix versions. Originally, the #! line was interpretted (only) by the shell(s).

    - tye        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-08-05 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (80 votes), past polls