[PATCH] #! and argv[0]: the path is removed ...

From: Andries.Brouwer@cwi.nl
Date: Thu Feb 17 2000 - 16:19:38 EST


Kevin Layer writes:

>> I hope this considered a bug.

Alan Cox answers:

> Im not sure about bug, but its certainly worth behaving the same way
> as everyone else in this case if its appropriate to do so.

> sure - send a patch

Kevin mentioned this patch:

--- linux-2.3.46/linux/fs/binfmt_script.c Tue Aug 3 19:18:39 1999
+++ linux-2.3.46a/linux/fs/binfmt_script.c Thu Feb 17 21:24:53 2000
@@ -47,8 +47,10 @@
        i_name_start = i_name = cp;
        i_arg = 0;
        for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
+#if 0
                if (*cp == '/')
                        i_name = cp+1;
+#endif
        }
        while ((*cp == ' ') || (*cp == '\t'))
                *cp++ = '\0';

and that is right. I hope his patch is applied.

This is an old discussion. Let me post my docs once more.
Every now and then I learn something new.

---------------------------------------------------------
1. The Linux situation:
If you have a script called bar, that starts with

        #!/some/path/foo lots of arguments

and the script is invoked using

        /some/other/path/bar x y z

then the program /some/path/foo is called with six arguments:

        0: "foo"
        1: "lots of arguments"
        2: "/some/other/path/bar"
        3: "x"
        4: "y"
        5: "z"

2. What do other systems do?

As far as I know, Linux is the only system that uses "foo"
as first argument. The other systems I checked all have

        0: "/some/path/foo"

(The above patch would bring Linux in line with Solaris etc.)

Concerning the #! line:
Linux truncates the #! line after 127 bytes.
SunOS 4.1.4 truncates the #! line after 32 bytes and has

        1: "lots of argumen"

SunOS 5.6 cuts at the space and has

        1: "lots"

Most systems agree with Linux. However, I just noticed that
BSDI 4.0 splits at spaces and creates separate arguments:

        0: "/some/path/foo"
        1: "lots"
        2: "of"
        3: "arguments"
        4: "/some/other/path/bar"
        5: "x"
        6: "y"
        7: "z"

The next argument (number 1 or 2 on most systems)
is the full pathname that was used to invoke the script.
However, on IRIX 5.3 and IRIX 6.2 I find

        2: "bar"

the stripped pathname only.
---------------------------------------------------------

In other words, the patch given above will "correct"
the only case where Linux differs from all systems
I tested, and will make Linux go with the majority
in all respects, but there remain differences.

Andries

PS1
POSIX says nothing about this.
 "Some systems can exec shell scripts. This functionality
  is outside the scope of this document."

PS2
Linux does not allow the #! interpreter to be
a shell script itself.

PS3
Of course: corrections and additions are welcome - aeb@cwi.nl

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Feb 23 2000 - 21:00:19 EST