Re: Script interpreter arguments

Guest section DW (dwguest@win.tue.nl)
Sun, 4 Jul 1999 04:31:47 +0200 (MET DST)


From: Khimenko Victor <khim@sch57.msk.ru>

> Why can a #! script only have 1 argument?

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"

> I know this. I even know what and where I can change to fix this.
> I wonder why it was developed this way... What does POSIX say?

POSIX does not specify what should happen.

> Ok. If POSIX says nothing we should ask: what other unix'es doing ?

The Unices I just checked (SunOS 4.1.4, SunOS 5.6, IRIX 6.2, Linux)
agree on the arguments after the first two.

Linux is the only one that starts with "foo" - the others start with
the full "/some/path/foo".

Concerning the most interesting part, argument 1, all agree that it is
absent when there are no parameters on the #! line.
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"
IRIX 6.2 agrees with Linux.

No doubt others will report on other systems.

So, for invocations that require more than one argument we may
have to use #!/bin/sh followed by the perl invocation on the next line.

Andries

-
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/