bug-bash
[Top][All Lists]
Advanced

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

Re: Execing perl?


From: William Bloom
Subject: Re: Execing perl?
Date: Wed, 11 Jul 2001 12:29:30 -0700 (MST)

Another observation to add to your note about this behavior...

I repeated your example on a FreeBSD 4.3 host, a RedHat
5.2 host, and a Solaris 8 host.  For all hosts, I tested
using an account that itself uses BASH 2.05.0(1) as the
login shell, all built from the same sources. I also used
this same shell behind #! in the sample script (on all these
systems, the BASH happens to be located in /usr/local/bin). 
Al three systems are running Perl 5.6.

I was able to reproduce the problem that you describe on the
RedHat host.  However, on the FreeBSD and Solaris hosts, the
same script behaves properly (exactly as described in the
perlrun man page).

Since this behavior is distinctly different on Linux than
from the other hosts, even though they're all three using
the same shell and the same script, I'm almost led to
believe that the Linux kernel is not applying 'word'
processing to the remainder of the line after the first word
(the command path) following #! during parsing.  Apparently,
FreeBSD and Solaris apply 'word' processing to the whole
line (using whitespace to delimit words).

I'm not a Linux heavy, but this is what the results suggest
to me.  This seems like a kernel issue rather than a shell
issue.  Is this configurable in Linux?


Bill

On 11 Jul 2001 14:50:19 -0400 Paul D. Smith <Paul D. Smith 
<pausmith@nortelnetworks.com>> wrote:

> OK, this isn't a bug, and it's also something that you'd _think_ would
> be so obvious it'd be right at the top of all the FAQs, etc... but I
> can't find it, nor can I figure it out.
> 
> 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
> 
> (ditto if I use /bin/bash instead).  This does work with other Bourne
> shells, though, such as Solaris' /bin/sh.
> 
> If I leave out the -- and just use the comment, I get this error:
> 
>   # -*-perl-*-: # -*-perl-*-: No such file or directory
> 
> (it doesn't ignore the comment).  Even moving this past the "normal"
> 32-char boundary doesn't help.
> 
> However, if I remove the extra stuff from the first line, then _Perl_
> screws up, due to this little gem (from perlrun):
> 
>        If the #! line does not contain the word "perl", the pro-
>        gram named after the #! is executed instead of the Perl
>        interpreter.  This is slightly bizarre, but it helps peo-
>        ple on machines that don't do #!, because they can tell a
>        program that their SHELL is /usr/bin/perl, and Perl will
>        then dispatch the program to the correct interpreter for
>        them.
> 
> As a result, /bin/sh runs Perl, which turns right around and tries to
> run /bin/sh, I guess with the options it got (-wS etc. etc.) and I get
> this:
> 
>   /bin/sh: -w: unrecognized option
> 
> 
> _Surely_ someone has solved this problem!
> 
> -- 
> -------------------------------------------------------------------------------
>  Paul D. Smith <psmith@baynetworks.com>    HASMAT--HA Software Methods & Tools
>  "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
> -------------------------------------------------------------------------------
>    These are my opinions---Nortel Networks takes no responsibility for them.
> 
> _______________________________________________
> Bug-bash mailing list
> Bug-bash@gnu.org
> http://mail.gnu.org/mailman/listinfo/bug-bash


--
William Bloom <william.bloom@pegs.com> (602) 906-7525
Pegasus Solutions, Inc.  7500 North Dreamy Draw Drive, Suite 120
Phoenix, Az 85020  http://www.pegs.com





reply via email to

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