SPUG: Buggy shebang-line parsing

David Dyck david.dyck at fluke.com
Sat Jan 15 09:10:29 PST 2005

On Fri, 14 Jan 2005 at 23:45 -0800, Tim Maher <tim at consultix-inc.com> wrote:

> I've found some serious bugs in recent Perl versions in the
> parsing of non-trivial shebang lines, involving option clusters after
> the first being disregarded if too many spaces precede the next ones,
> and the -s option being ignored altogether, if it doesn't come first
> in some cases.  For example:
> 	#! /usr/bin/perl -wlnaF'\t' -s 	# BAD!
> 	#! /usr/bin/perl -s -wlnaF'\t'	# GOOD!


Have you eliminated the operating system interaction with the command line?
 (I see that you are close to 32 characters and perlrun has some warnings
  about it - see below)

Do you need the space between the #! and the interpreter name?

Does moving the flags past the 32-character have an effect?

I see you are trying to build a test program, but do you have
a few short ones that show a good and bad example?


>From perldoc perlrun here are some concerns:

   Because historically some operating systems silently chopped off kernel
    interpretation of the #! line after 32 characters, some switches may be
    passed in on the command line, and some may not; you could even get a "-"
    without its letter, if you're not careful. You probably want to make sure
    that all your switches fall either before or after that 32-character
    boundary. Most switches don't actually care if they're processed
    redundantly, but getting a "-" instead of a complete switch could cause
    Perl to try to execute standard input instead of your program. And a
    partial -I switch could also cause odd results.

    Some switches do care if they are processed twice, for instance
    combinations of -l and -0. Either put all the switches after the
    32-character boundary (if applicable), or replace the use of -0digits by
    "BEGIN{ $/ = "\0digits"; }".

More information about the spug-list mailing list