Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Shebang Line (was: different first line in perl)

by Intrepid (Deacon)
on Sep 29, 2006 at 10:13 UTC ( #575497=note: print w/replies, xml ) Need Help??


in reply to different first line in perl

greatshots sought to understand that which is described by the following text:

[...] in a very old application called npr [...] I have picked the following snippet from there and ask for your valueable inputs about it. #!`which perl` The above code works fine in Solaris ksh. Is that a appreciatable line in perl ? have anyone of you already used such a line in your perl codes ? can I use those line in my future codes ?

I would say not. It is a thing i don't think i have seen before, but it does something similar to what is done by a much more recent and sound first-line: #! /usr/bin/env perl

Points to understand:

  • This is called "the shebang line" in Perl culture, or alternately the "sharpbang" or the "hash-bang".

  • This is not Perl code. It is not really shell code either. This first line is a means by which, only under Unix systems, a Unix OS kernel can determine which interpreter to run this script under. If the shell becomes involved in this process at all, and I suppose under some very ancient Unix made by some vendor in the benighted depths of history, that could happen, then one might see the shell execute which perl and report back to the kernel what path to use for invoking the Perl interpreter.

  • Non-unix systems like MS Windows do not care about this line, except that the Perl intepreter on those systems sees the line and if there are some switches like -w after the tokens perl, it will take note of them as it would if they had appeared on the commandline.

  • /usr/bin/env perl does them same thing as `which perl` might have done in this obsolete Unix context, on modern Unix systems, without the involvement of the shell.

Caveat: I am not a Unix guru of 30 years experience and I don't warrantee that every aspect of this reply is correct.

If you want the best advice I can give you based on my own understanding, use #! /usr/bin/env perl (but no switches allowed after 'perl'). The space between the ! and the /usr/bin... is deliberate. It caters to the dysfunction of a legacy Unix flavor (I think it is an HPUX) that didn't do correct kernel intepretation of the shebang without the space. It does not harm correct operation of any other known Unix flavor.

    Soren A / somian / perlspinr / Intrepid

-- 
Words can be slippery, so consider who speaks as well as what is said; know as much as you can about the total context of the speaker's participation in a forum over time, before deciding that you fully comprehend the intention behind those words. If in doubt, ask for clarification before you 'flame'.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-05-10 22:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (108 votes). Check out past polls.

    Notices?