Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

A shebang line conundrum

by inelukii (Sexton)
on Oct 04, 2002 at 20:46 UTC ( #202893=perlquestion: print w/ replies, xml ) Need Help??
inelukii has asked for the wisdom of the Perl Monks concerning the following question:

While technically not a perl question, here goes...

At my company, we work on Linux and SGI machines. For some unknown reason, perl is installed in /usr/bin/perl on Linux and /usr/local/bin/perl on SGI. Needless to say, this is extremely cumbersome when you want to run the same script on either OS. Our current solution is to have two versions of the script and have users execute a csh script that checks the OS type and calls the perl script with the appropriate #! line. Other than the #! line, the code is identical. Of course, whenever I update one, I have to copy it to the other and change the #! line. This is annoying.

Does anyone know of a way around this other than pestering my sysadmins to fix the location?

Thanks

Comment on A shebang line conundrum
Re: A shebang line conundrum
by blakem (Monsignor) on Oct 04, 2002 at 20:54 UTC
    A simple symbolic link would fix the problem:
    On the SGI machines # ln -s /usr/local/bin/perl /usr/bin/perl
    Surely that can't be too much to ask of the sysadmins...

    -Blake

      You'd think so, but I have been requesting that link for two weeks now and am not holding my breath. :/
Re: A shebang line conundrum
by kabel (Chaplain) on Oct 04, 2002 at 20:57 UTC
    if there are few machines, a symbolic link should IMO do it (give it a try, i don't know it since i can't test it)
    ln -s /usr/local/bin/perl /usr/bin/perl
    on the sgi's and then change everything to /usr/bin/perl.

    HTH
Re: A shebang line conundrum
by sschneid (Deacon) on Oct 04, 2002 at 21:03 UTC
    Here's a unique workaround that I've come across in the past-- replace #!/usr/local/bin/perl or #!/usr/bin/perl (or whatever) with the following:
    eval 'exec perl -S $0 "$@"' if 0; # Rest of code goes here
    Hope it helps.

    scott.
      Should have mentioned this in the original post, but the SGI machines have two versions of perl. Unfortunately, "perl" on the SGIs invokes the old 4.x version; otherwise this solution would work great.

      Thanks
        You can say this:
        #!/usr/bin/env perl
        If you make sure the right perl is first in your path, it will run that. This is all in the perlrun manpage.
      How does that work?
Re: A shebang line conundrum
by VSarkiss (Monsignor) on Oct 04, 2002 at 21:20 UTC

    So, based on the other posts, you can't get your BOFH to install a symbolic link, and the SGI machines have both Perl 4 and Perl 5, and the default path invokes Perl 4.

    A couple of other things to try:

    1. If you can change the default path on the SGIs, put the Perl 5 directory first, then use the eval 'exec perl ...' if 0 trick.
    2. Use the "pack up the dirt in another script" idea, but in reverse. In other words, write a shell script perlwrap, which on the Linux machines contains
      #! /bin/bash exec /usr/bin/perl $*
      and on the SGI machines contains:
      #! /bin/sh exec /usr/local/bin/perl $*
      Then you can preface your scripts with #! /usr/local/bin/perlwrap
      (or whever you put it). At least this way you can deploy the same Perl script, and your users can just type the script name. Yeah, it's ugly, and needs more maintenance than the symlink, but it should work.

    Personally, I'd keep trying the path and/or symlink thing before I resort to that second option.

    Update
    Nevermind, read perrin's note above. I kept thinking there was a better way....

      Thanks for all the suggestions, Perrin's suggestion is working and will make my life easier until I eventually get my symlink.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-07-25 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls