The short answer is: this isn't possible with env — at least not in any portable way...

The problem is that the kernel (which is handling shebang execution) typically only has very rudimentary argument parsing facilities, i.e. it parses the shebang line into an interpreter and one optional argument. In your specific case, this means that /usr/bin/env would be passed "perl -wT" as a single argument, if you were to try something like

#!/usr/bin/env perl -wT

as you might have extrapolated from studying the env manpage.

(Though, as far as I remember, there's one notable exception - Solaris - which does actually handle this correctly, by passing multiple arguments to the interpreter.)

Thing is that env is not doing any further argument splitting on its own, so it would try to execute a program named "perl -wT", which would of course fail under normal circumstances...  There isn't much you can do about it.

However, if the idea is to avoid hardcoding the absolute path to Perl, you could use the shell (instead of /usr/bin/env), in combination with Perl's option -x, e.g.

#!/bin/sh exec perl -Sx -T $0 "$@" #!perl -w # Perl code starts here print "interpreter: $^X\n"; print "script: $0\n"; print "arguments:\n"; printf " '%s'\n", $_ for @ARGV;

-x makes Perl skip any non-perl garbage up to #!perl. -S would make the script be found along the search path (if so desired).

Option -T would have to go on the exec perl ... command line (as shown), while other options (like -w) could also go on the #!perl line.

Also see perlrun for other similar hacks/wrappers...


In reply to Re: calling perl via env.... by almut
in thread calling perl via env.... by perlknight

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.