Bug in #! processing

Sławek Żak zaks at prioris.mini.pw.edu.pl
Thu Sep 30 04:59:51 PDT 2004

Ceri Davies <ceri at submonkey.net> writes:

> On Wed, Sep 29, 2004 at 01:47:06PM +0200, S?awek ?ak wrote:


>>     You should speel buggy as 'POSIX' in this case I guess.

> You're actually guessing though, right?  I can't find this in the
> standard; if you know it's there then I'd appreciate a reference.

    No reference on this. Vague memories of brokedness only.


>>     This behavior is mandated by POSIX which, as I reckon, allows passing of
>>     only the first argument to the interpreter.
> Are you guessing again?

> I believe that the FreeBSD behaviour is closer to "correct" than
> anything else we're seeing in this thread.  I should be able to specify
> 	#!/usr/bin/perl -w -0
> or whatever without having everything other than the first argument
> ignored.

    Would be nice. I admit. I like the bahavior of FreeBSD besides special
    treatment of # on the first line after #!. Allowing for comments on the
    first line is a strange excuse. Have you ever seen a script commenting on
    the interpreter execution or had a need to do so?
>>     It is confirmed by other
>>     supposedly compliant systems. I've checked before AIX 5.2, Solaris 8/9. Two
>>     raisins in the pie are Tru64 5.1B and HP-UX 11, which return some erm,
>>     strange results. For such script:
>> #!./main 1 2 3 -#!
>> print ok
>>     You get:
>> Main.c test
>> ./main
>> 1 2 3 -#!
>> ./tst.sh
> Linux 2.4.20 does this too.

    That's as silly as can get. When called as:

           interpreter -a1 -a2 -a3 script

    the argument parsing done by interpreter must be different then when invoked
    via #! mechanics. Argh!
>>     The behavior I'd like to have, and which seems correct is not bothering with
>>     second, 3rd and so on occurence of #! in the first line of script. Feasible?
>>     I guess so. The only commercial product on my systems uses -#! switch on all
>>     platforms as a script file mark.
> That seems wrong too.  #! shouldn't be magic anywhere other than at the
> beginning of a file.

    Do you think that -#! argument is magic? Why is it so? It's not magic and
    should be passed without exec(2) interference.
>>     I don't see any explanation for current
>>     behavior therefore I'm reporting it.
> The explanation is that we only process that line up to a '#' or
> newline.  Backing out revision 1.21 of sys/kern/imgact_shell.c is one
> fix, or perhaps allowing a '#' character to be escaped.  I'm not sure if
> I see an overwhelming reason for either.

    I don't see a convincing use for comments on the first line of script. Hash
    is special already when treated as comment character. # is not a comment in
    any `scripting language'. It is a shell legacy and shouldn't be forced on
    the remaining universe.


More information about the freebsd-current mailing list