bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Execing perl?


From: Paul Jarc
Subject: Re: Execing perl?
Date: Wed, 11 Jul 2001 15:10:58 -0400
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

"Paul D. Smith" <address@hidden> writes:
> The Perl docs (perlrun) say you can use this stanza to write a perl
> script when you don't know where the perl runtime will be; something
> like:
> 
>   #!/bin/sh -- # -*- perl -*-
>   eval 'exec perl -wS $0 ${1+"$@"}'
>     if $running_under_some_shell;
> 
> This doesn't work if bash is /bin/sh; I get this error:
> 
>   /bin/sh: -- # -*-perl-*-: unrecognized option

This will break *any* interpreter, as long as it's on Linux.  Linux
passes everything after the first space as a single argument to the
interpreter.  The eval stuff isn't what you want anyway, and I don't
think it ought to be used that way in the perlrun man page.  It's
meant to be used like this:
  #!/path/to/perl
  eval 'exec perl -wS $0 ${1+"$@"}'
    if $running_under_some_shell;
Then if you have something like csh that tries to interpret the script
itself instead of simply passing the script name to execve, it'll
still become perl.

The next example in the perlrun man page is what you want:
#!/usr/bin/env perl
This assumes a location for env, but searches for perl in $PATH.


paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]