This is really a shell question, not a Perl question, but for reasons that are hopefully obvious, it can't be done in Perl.

In our NFS environment we have various different platforms (Linuxes and AIX) sharing a common filesystem. It's useful to have central builds of certain programs - Perl being a good example, because it lets us have centrally installed modules too.

So let's say that we have

/nfs/perl/5.10/centos4/bin/perl

and

/nfs/perl/5.10/centos5/bin/perl

(The user environment is automatically set up so that the correct perl for their host is in the path.)

What I want to do is create a

/nfs/perl/5.10/bin/perl

which checks the platform of the current host, and starts the correct perl interpreter. I want it to work in a hash-bang line, and support command line parameters etc. Basically it should be invisible to the user that they aren't hitting the actual Perl binary directly.

I thought I had this working, with this script:

#!/bin/sh . /etc/host.conf exec /nfs/perl/5.10/${HOST_PLATFORM}/bin/perl "$@"

In fact, this seems to work on the majority of machines. But there are some machines where it doesn't work at all when used in a hash-bang line. Instead of starting perl and running the script with that, it tries to run the perl script through /bin/sh, with the entertaining but unproductive results that you would probably expect.

I can't see any pattern for which hosts work and which don't, though many have custom kernels which might be a factor.

Does anyone know of an alternative way to write this wrapper script which might be more reliable?


In reply to Can I write a transparent shell wrapper to start the correct build of Perl? by thparkth

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.