This page is from Sven Mascheck. Find the latest version at www.in-ulm.de/~mascheck

#! - Some details about the shebang mechanism on various Unix flavours


Here you'll find:


More reading:


Some specialities:


Test results on various systems:

I was using the following as program "showargs":

	#include <stdio.h>
	int main(int argc, char** argv) {
	    int i;
	    for (i=0; i<argc; i++)
		fprintf(stdout, "argv[%d]: \"%s\"\n", i, argv[i]);
	    return(0);
	} 

and a one liner script "invoker.sh" to call it, similar to

	#!/tmp/showargs -1 -2 -3 

to produce the following results (tried them myself, but i'd like to add your results from yet different systems).

Typically, a result from the above would look like this:

	argv[0]: "/tmp/showargs"
	argv[1]: "-1 -2 -3"
	argv[2]: "./invoker.sh"
...but the following table lists the variations, the meaning of the columns is explained below.
                  | maximum  |cut-off(c)|only the|each arg|invoker in|not full
                  | length of|error(err)|1st arg |in its  |argv[0]   |path in
                  | shebang- |or ENOEXEC|        |own     | (not the |argv[0]
                  | line:    |( )    [1]|        |argv[x] |  invoked)|
------------------+----------+----------+--------+--------+----------+-------
AIX 3.2.5         | > 80     | [2]      |        |        |          | [2]
AIX 4.3.2         | > 80     |          |        |        |          |  X
FreeBSD 4.3(alpha)|   64     |          |        | X      |          |
FreeBSD 4.5(alpha)| > 80     | err      |        | X      |          |
HP-UX A.08.07     |   32     |          |        |        | X        |  -
HP-UX B.09.03     |   32     |          |        |        | X        |  -
HP-UX B.10.10     | > 80     | [3]      |        |        |          | [3]
HP-UX B.10.20     | > 80     |          |        |        |          |
IRIX 5.3          | > 80     | err      |        |        |          |
IRIX 6.5          | > 80     | err      |        |        |          |
Linux 2.2.9 (x86) | > 80     |  c       |        |        |          |  X
MUNIX 3.1 (SVR3.x)|   32     |          |        |        | X        |
NetBSD 1.5(alpha) |   64     |          |        |        |          |
OpenBSD 2.9       |   64     |          |        |        |          |
OSF1 V4.0(alpha)  | > 80     |          |        |        |          |  X
OSF1 T5.1(alpha)  | > 80     |          |        |        |          |  X
Sinix 5.20        |   32     |          |        |        |          |
SunOS 4.1.4(sparc)|   32     |  c       |        |        |          |
SunOS 5.x(sparc)  | > 80     |          | X      |        |          |
Ultrix 4.5        |   80     |  ?       | X      |        |          |


Meaning of the columns:

Footnotes in the table:
[1] If the shebang line is too long, three things can happen:
  • The line gets truncated
  • Due to a returned E2BIG/ENAMETOOLONG, you get something like "Arg list too long"/"Arg list or environment too large" or "File name too long", respectively.
  • You get ENOEXEC (which usually results in a rather silent failure in shells).

[2] If the shebang line exceeds 255 characters, it gets cut down to exactly 80 characters--or the first argument, if this is shorter. If the shebang line was not too long, argv[0] is the basename of the invoked program, otherwise the absolute path.

[3] If the shebang line exceeds 128 characters, it gets cut down to exactly 80 characters--or the first argument, if this is shorter. If the shebang line was not too long, argv[0] is the invoking, otherwise the invoked program.


And why shebang? In music, '#' means sharp. So just shorten it to sharp-bang. Or it might be derived from "shell bang". All this probably under the influence of the american slang idiom "the whole shebang" (everything, the works). See also the jargon dictionary for the latter explanation.


22-05-2002

../