[Python-Dev] [offtopic] /usr/bin/env vs linux

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Sat, 4 Aug 2001 22:52:12 +0200

> This is age-old.  The kernel only passes on one argument (and it has
> to be of limited length).  In "/usr/bin/env python", "python" is
> that one argument.  I guess there's a really good reason (like
> resource constraints) for this or it would've been fixed ages ago,
> wouldn't it?

It's in fs/binfmt_script.c, which I wrote about five years ago. The
specific code is around

	 * OK, we've parsed out the interpreter name and
	 * (optional) argument.
	 * Splice in (1) the interpreter's name for argv[0]
	 *           (2) (optional) argument to interpreter
	 *           (3) filename of shell script (replace argv[0])
	 * This is done in reverse order, because of how the
	 * user environment and arguments are stored.

AFAICS, there is no good reason to limit this to a single argument,
except for laziness. I copied this fragment from the earlier #!
implementation by tytso, and did not question it.

OTOH, the size constraint comes from BINPRM_BUF_SIZE, which is
128. The kernel only offers this much data initially to a binary
format module for format detection, and the binfmt_script driver
doesn't attempt to read any further data from disk (which it could, if
it wanted to).

It seems that Single Unix does not mandate any behaviour in this
respect; #! is still but a common extension. On Solaris, #! is
documented in exec(2) as

#! pathname [arg ]

so I guess Linux was just following SunOS once more here.