[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
shebang length limits
shebang length limits
Fri, 05 Sep 2014 08:09:40 -0400
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.0
-----BEGIN PGP SIGNED MESSAGE-----
What exactly is the limit on the length of a shebang line in an
executable script, when called from within bash?
Most of what I read seems to indicate that it should be either 127
characters or kernel-dependent (and probably still 127 characters), but
a few things seem to indicate that it might be 80 characters instead.
I have a script whose shebang line, including the #! at the beginning,
comes to exactly 129 characters. This is above both limits; attempting
to run the script fails.
If I move the executable targeted by the script to a different location
and modify the shebang line appropriately (doable for testing purposes
but not really practical for regular use - this is from a build system),
it is now only 85 characters. This is above the 80-character limit but
below the 127-character one; attempting to run the script succeeds.
At a glance, that would seem to indicate that the 127-character limit is
what applies. However, in the 129-character test case, the exact failure
message prints only the first 79 characters of the shebang line,
followed by "bad interpreter: No such file or directory". That would
seem to indicate that it is trying to look for the path which it
printed, which naturally is truncated and so does not exist.
Thus, the error message I get with a 127-character path and
129-character shebang seems to indicate a 79- or 80-character shebang
length limit, but the fact that the script succeeds with an 83-character
path and 85-character shebang seems to indicate an at-least-85-character
shebang length limit. This is somewhat confusing.
What is the actual length limit, and what is the cause of this confusion?
My best hypothesis so far is that the actual length limit is 127
characters, but that when printing the 'bad interpreter' error, bash
truncates the printed shebang line to 80 (or 79) characters. That would
explain the observed behaviors, but such a mismatch would seem
unnecessarily confusing and misleading, since it A: gives a "No such
file or directory" message for a path that (in this scenario) nothing
ever actually tried to access, and B: indicates a lower apparent limit
than what actually exists.
If that isn't what's going on, then I'm stumped for the moment.
Secrecy is the beginning of tyranny.
A government exists to serve its citizens, not to control them.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
-----END PGP SIGNATURE-----
- shebang length limits,
The Wanderer <=