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

From: Khimenko Victor (khim@sch57.msk.ru)
Date: Tue Feb 29 2000 - 13:30:47 EST


In <UTC200002172119.WAA10213.aeb@arend.cwi.nl> Andries.Brouwer@cwi.nl (Andries.Brouwer@cwi.nl) wrote:
> 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.

Since there are no standards the only way is to use other systems and guide
and think about whole problem. I know I wanted quite a few times to put FEW
additional arguments for script. I NEVER needed one argument with spaces.

> 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 : Tue Feb 29 2000 - 21:00:23 EST