SPUG: Bug in shebang parsing?

Tim Maher tim at consultix-inc.com
Mon Jul 5 18:54:47 CDT 2004


On Mon, Jul 05, 2004 at 04:36:25PM -0700, Fred Morris wrote:
> m3047 at devil:~ > perl -v
> 
> This is perl, version 5.005_03 built for i586-linux
> 
> Copyright 1987-1999, Larry Wall
> 
> Perl may be copied only under the terms of either the Artistic License or the
> GNU General Public License, which may be found in the Perl 5.0 source kit.
> 
> Complete documentation for Perl, including FAQ lists, should be found on
> this system using `man perl' or `perldoc perl'.  If you have access to the
> Internet, point your browser at http://www.perl.com/, the Perl Home Page.

Your first test section below seems to prove that the bash shell doesn't
interpret Perl code very well, which is gratifying to see 8-}
(Shebang lines typed interactively don't do what they do in scripts).

And with the script tests that follow, my recommended invocation is:
"./scriptname -switch" , so you can see if the switch argument gets
removed from @ARGV (or not).  Despite these niggles, it appears that
the "perl -w  -s" invocation didn't even get the -w option enabled
in your 5.005_03 tests, which at least works in the newer versions
I tried (although the -s was still ignored).

-Tim
 
> m3047 at devil:~ > #! /usr/bin/perl -s -w
> m3047 at devil:~ > $switch == 1;
> bash: ==: command not found
> m3047 at devil:~ > warn "Arguments are: @ARGV";
> bash: warn: command not found
> m3047 at devil:~ > # :-p
> m3047 at devil:~ > cd perl
> m3047 at devil:~/perl > mkdir tim-space
> m3047 at devil:~/perl > cd tim-space
> m3047 at devil:~/perl/tim-space > cat > one_space_sw
> #! /usr/bin/perl -s -w
> $switch == 1;
> warn "Arguments are: @ARGV";
> m3047 at devil:~/perl/tim-space > chmod a+x *
> m3047 at devil:~/perl/tim-space > ./one_space_sw
> Useless use of numeric eq in void context at ./one_space_sw line 2.
> Name "main::switch" used only once: possible typo at ./one_space_sw line 2.
> Use of uninitialized value at ./one_space_sw line 2.
> Arguments are:  at ./one_space_sw line 3.
> m3047 at devil:~/perl/tim-space > cat > one_space_ws
> #! /usr/bin/perl -w -s
> $switch == 1;
> warn "Arguments are: @ARGV";
> m3047 at devil:~/perl/tim-space > chmod a+x *
> m3047 at devil:~/perl/tim-space > ./one_space_ws
> Useless use of numeric eq in void context at ./one_space_ws line 2.
> Name "main::switch" used only once: possible typo at ./one_space_ws line 2.
> Use of uninitialized value at ./one_space_ws line 2.
> Arguments are:  at ./one_space_ws line 3.
> m3047 at devil:~/perl/tim-space > cat > two_spaces_sw
> #! /usr/bin/perl -s  -w
> $switch == 1;
> warn "Arguments are: @ARGV";
> m3047 at devil:~/perl/tim-space > chmod a+x *
> m3047 at devil:~/perl/tim-space > ./two_spaces_sw
> Arguments are:  at ./two_spaces_sw line 3.
> m3047 at devil:~/perl/tim-space > cat > two_spaces_ws
> #! /usr/bin/perl -w  -s
> $switch == 1;
> warn "Arguments are: @ARGV";
> m3047 at devil:~/perl/tim-space > chmod a+x *
> m3047 at devil:~/perl/tim-space > ./two_spaces_sw
> Arguments are:  at ./two_spaces_sw line 3.

What?  The warnings don't seem to have been enabled for this script.
How could that be, with -w  -s?  Looks like 5.005_03 has an even
more serious version of this bug.

> m3047 at devil:~/perl/tim-space >
> 
> 
> HTH...
> 
> --
> 
> Fred Morris
> fredm3047 at inwa.net (I-ACK)
> 
> 
> _____________________________________________________________
> Seattle Perl Users Group Mailing List  
> POST TO: spug-list at mail.pm.org  http://spugwiki.perlocity.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location Unknown
> WEB PAGE: http://www.seattleperl.org

-- 
*--------------------------------------------------------------------------*
| Tim Maher, CEO     (206) 781-UNIX      (866) DOC-PERL     (866) DOC-UNIX |
| tim(AT)Consultix-Inc.Com  http://TeachMePerl.Com  http://TeachMeUnix.Com |
*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
| UPCOMING CLASSES: "UNIX Fundamentals for Power Users", 6/28-7/1, Seattle |
| Watch for my upcoming book: "Minimal Perl for Shell Users & Programmers" |
*--------------------------------------------------------------------------*



More information about the spug-list mailing list