Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: How do I use 'which' in the hash-bang line?

by davies (Prior)
on Mar 15, 2018 at 15:06 UTC ( [id://1210965]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I use 'which' in the hash-bang line?
in thread How do I use 'which' in the hash-bang line?

Note that env does not allow the passing of parameters to the target, so that #!/usr/bin/env perl -w does not work. At least, this was true the last time I tried.

Regards,

John Davies

Replies are listed 'Best First'.
Re^3: How do I use 'which' in the hash-bang line? (updated x2)
by haukex (Archbishop) on Mar 15, 2018 at 15:13 UTC

    <update2> Sorry, I got so caught up in the point I was trying to make - that Perl scans the shebang line even when running the script as perl test.pl - that I missed the limitation that the AM pointed out below, that you are right that #!/usr/bin/env perl -w does in fact not work when invoking the script via ./test.pl. </update2>

    so that #!/usr/bin/env perl -w does not work

    It does for me:

    $ cat test.pl #!/usr/bin/env perl -wls print $x+undef; $ perl test.pl -x=5 Use of uninitialized value in addition (+) at test.pl line 2. 5

    From perlrun: 'The #! line is always examined for switches as the line is being parsed. ... Parsing of the #! switches starts wherever "perl" is mentioned in the line.'

    (I'm not sure about the history of this feature at the moment.) Update: The description of this feature was in perl-5.000, although apparently the support for which options are supported there has changed, for example perl58delta says "The command-line options -s and -F are now recognized on the shebang (#!) line." or perl5100delta says "The -C option can no longer be used on the #! line." (Although as choroba pointed out and as the docs say: "It wasn't working there anyway, since the standard streams are already set up at this point in the execution of the perl interpreter.")

      Try:

      $ chmod a+x test.pl $ ./test.pl

      The env utility *supports* passing arguments to the command .... if invoked from command line (with args split by shell). As part of shebang, however, all following arguments are passed to env as a single string. So if you don't have a command such as "perl -wls" on the $PATH, the result is a failure.

        As part of shebang, however, all following arguments are passed to env as a single string.

        That's a very good point, I've edited my post, thanks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-19 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found