Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Do you know where your variables are?
 
PerlMonks  

Re: The basics

by Anonymous Monk
on Jun 24, 2006 at 14:47 UTC ( [id://557399]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to The basics

what is the use of #!/usr/bin/perl other than to interpreter?

Replies are listed 'Best First'.
Re^2: The basics
by Joost (Canon) on Jun 24, 2006 at 15:17 UTC
    The #! line has two programs that "interpret" it:
    • To the shell. An executable file that starts with a #! line will cause the executing shell to start up the program indicated in that line. That way, you can use #!/bin/sh to create a shell script, #!/usr/bin/perl to create a perl script etc. At least on unixish systems, there is always a shell involved in this process (but for instance windows doesn't work like that)

    • (Possibly) to the interpreter indicated in the #! line.

      For instance, perl reads the additional arguments on the #! line as a sort of "setup parameters". Example: #!/usr/bin/perl -wT will run perl with global warnings enabled and in taint mode.

      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

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

        - tye        

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://557399]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.