To the best of my knowledge, you cannot have two levels of shebang-activated programs. So if you run ./test.pl which starts with #!/some/program, then /some/program cannot also be a shebang program.

The solution (or at least a solution) is to call /usr/bin/env, which itself does shebang-emulation, instead of calling your wrapper directly.

/path/to/perlwrapper:

#!/usr/bin/perl print "wrapper about to execute @ARGV\n"; exec "/usr/bin/perl", @ARGV;
test.pl:
#!/usr/bin/env /path/to/perlwrapper print "hello world!\n";
And then executing ./test.pl should work (at least, it did for me). Changing all your scripts to use env in their shebang line is a pain (you cannot just repace /usr/bin/perl with your wrapper), but it's the only way you can emulate nested shebangs. Otherwise, you'd have to make this version-delegation wrapper into a compiled binary.

There are also further complications: It appears that if the shebang line doesn't contain the word "perl", then perl itself will try to emulate shebangs and start an infinite loop (re-invoking your version-delegation wrapper). So I got weird results when I first named it "wrapper" instead of "perlwrapper"...

blokhead


In reply to Re: Conditionally executing different versions of Perl by blokhead
in thread Conditionally executing different versions of Perl by suaveant

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.