It is currently Thu, 20 Jan 2022 03:53:21 GMT



 
Author Message
 #!/usr/local/bin/perl -w || /usr/bin/perl -w
On Solaris 8, an old version of Perl is installed in
/usr/bin/perl, and a new version in /usr/local/bin/perl.

I want to use the newer version if it is there, otherwise
I want to use the older version. How do I convey the idea
in #! line?

#!/usr/bin/env perl
isn't an option as it depends on the user's PATH, which is not a good
idea for non-interactive use. For the script maybe run on cron or other
schedulers. It is better to make the script self sufficient. That is,
it should be able to run with "env -i ./script".

I did read the Perl book (3rd ed) page 488, but no solution is provided
there.



 Thu, 14 Aug 2003 11:42:16 GMT   
 #!/usr/local/bin/perl -w || /usr/bin/perl -w
Michael Wang wrote in comp.lang.perl.misc:

You can try this :

#!/usr/bin/perl
use Config;
if ($Config{version} =~ /^5\.0/ && -x '/usr/local/bin/perl') {
  exec('/usr/local/bin/perl', $0, @ARGV) or die $!;
... the script here ...

Note that switches found on the shebang line will not be applied when
/usr/local/bin/perl is used.

Note also that this method is not very efficient...

--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/



 Fri, 15 Aug 2003 17:30:39 GMT   
 #!/usr/local/bin/perl -w || /usr/bin/perl -w

Thanks. This solves the problem that

if /usr/local/bin/perl is there
  use it
else
  use /usr/bin/perl  # and we know that it is there
fi

if the question is changed to

if /usr/local/bin/perl is there
  use it
elif /usr/bin/perl is there
  use it
fi

And we only know at least one of /usr/local/bin/perl and /usr/bin/perl
is there but not know which one is there.

I think this has be to

#!/bin/ksh

and some smart construct understandable for both ksh and perl.



 Fri, 15 Aug 2003 21:21:15 GMT   
 #!/usr/local/bin/perl -w || /usr/bin/perl -w

You could try something like this:

#!/bin/zsh -- # -*- perl -*-
eval 'PATH="/usr/local/bin:/usr/bin"; exec perl -wS $0 ${1+"$@"}'
  if 0;

and adjust the shell line accordingly (I couldn't get it to work
right with ksh on my box, though).

HTH
--
Joe Schaefer     "The eternal mystery of the world is its comprehensibility."
                                               --Albert Einstein



 Sat, 16 Aug 2003 01:28:09 GMT   
 #!/usr/local/bin/perl -w || /usr/bin/perl -w

You can put a symbolic link there so that /usr/local/bin/perl always
exists.

--
        Bart.



 Sat, 16 Aug 2003 01:58:51 GMT   
 
   [ 5 post ] 

Similar Threads

1. /usr/local/bin/perl ->/usr/bin/perl

2. #!/usr/bin/perl or #!usr/bin/perl

3. /bin /usr/bin /usr/local/bin etc

4. /usr/bin/ls /usr/ucb/ls /usr/local/bin/ls

5. /usr/local/bin vs. /usr/bin

6. gnu/usr.bin/perl/perl - ?!?!?!

7. dynamic linker: /usr/local/bin/perl: symbol not found: dlopen

8. relationship between /usr/bin/adb and /usr/bin/ps

9. /usr/xpg4/bin/tr bug (or don't use /usr/xpg4/bin)

10. /usr/dt/bin/dtksh and /usr/bin/ksh


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software