http://qs1969.pair.com?node_id=195488

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to run some perl script on diffrent enviroment Linux and unix. They all have diffrent path to perl. So I tried to use the shebang stuff mentiond in perldoc.
#!/bin/sh -- # -*- perl -*- -p eval 'exec perl -wS $0 ${1+"$@"}' if 0;
This works great in unix but not att the Linux redhat 7.2 machine. There I get the error
/bin/sh: -- # -*- perl -*- -p: unrecognized option Usage: /bin/sh [GNU long option] [option] ... /bin/sh [GNU long option] [option] script-file ...
I think I sneak in another question when I at it. What do you do when you creat an accont and you misspell the email adress so you do not get the mail with the initial password. I realy liked the nickname that I chose and would rather stick to it. Where should I send this question to get some wisdom in my unlighten world?

Replies are listed 'Best First'.
Re: shebang and linux RH
by sauoq (Abbot) on Sep 05, 2002 at 20:58 UTC

    You might try it with the "env" program trick:

    #!/usr/bin/env perl

    In the long run, putting perl or a link to it in a standard place like /usr/bin would be a better idea. If you can't do that, then editing the script to use the right shebang is still probably better than launching it via sh or env. If perl is in your path, it's a one-liner:

    perl -i -pe '$_="#!`which perl`" if $.==1' your_script
    -sauoq
    "My two cents aren't worth a dime.";
    
Re: shebang and linux RH
by bluto (Curate) on Sep 05, 2002 at 21:30 UTC
    I tend to use something similar ...

    : #-*-cperl-*- eval 'exec perl -wS "$0" ${1+"$@"}' if 0;

    I found that the /usr/bin/env trick doesn't work on every machine I care about while the one above does.

Re: shebang and linux RH
by VSarkiss (Monsignor) on Sep 05, 2002 at 21:35 UTC

    If you can live without automatically enabling Perl mode in emacs, it should work to just trim off the stuff following the --, like this:

    #!/bin/sh -- eval 'exec perl -wS $0 ${1+"$@"}' if 0;
    I'm away from my RH box, so I can't test this.

    As to your second question, you can post a note to Editor requests, or send an email to The Grand Abbot (there's a mailto: link at the bottom of every page).

Re: shebang and linux RH
by rir (Vicar) on Sep 06, 2002 at 04:45 UTC
    The location of interpreter problem annoyed me
    enough to write hbb on linux. This used #!! as a
    flag to invoke a program using a HBB_PATH defined
    by the admin.

    The idea is: if, say, perl isn't installed by
    the admin, it seems rude, possibly dangerous, for a
    script to run whatever interpreter it happens to find
    in Joe User's PATH.

    A consensus of one was reached.