bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

shebang length limits


From: The Wanderer
Subject: shebang length limits
Date: Fri, 05 Sep 2014 08:09:40 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

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.

- -- 
   The Wanderer

Secrecy is the beginning of tyranny.

A government exists to serve its citizens, not to control them.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJUCagEAAoJEASpNY00KDJrp+cP/2VMR/lNVMVyFCznAY5Q4NM8
F7ZykrlMvm8ZdLPdOnBEkYzKpikPue+WxiFWBr3LfOrB9QMJdkZb5tfAVa/Qwe4j
adqKkJcBn6sj4JweJXPDO7Wju7/AcvGaNwIke5aM6LPrthIFdObpqemvxRMigwfE
Q9u15OpaxwHmLJ6wrx++Wi6VbxuG0K0ctWTV4JQloadPizHwIF6yWSLZxTn7MpJp
GWregvxyJ/tQey8NLPPGd6lg1riloFO2TcLX4b5yaAsl5Hzlw58k5fuFU/kdQYeC
eHEeAZ1jPLMFDZgpfZettw2PvcSflPVvEsA291Lis44nBi83qe/ehv5ReoVYGRzE
v1p14tgn2HWo3N8Xwl8QnHJ7+OF94jUJDZ6svK3XX+STwRpGx2gwGBNrNyhphAla
/Yu0fE8wQCOt3nCorBT4c9OslfYgn45h2dWhjsKHfWOczHw3koXoRoIGiomPcrSW
ps5VMR1JVEcTBoMQLIlbjoxHz6OnpCv9Q7pglMKlkn7mAybDNjVE8uXxgYw5cg4C
Jl+gemCTeseVGZfsNwjwEwoBrlqPU3aWtB+HQ9DjXrjCyrE/+2iADgsGeOt/DxAg
ANECb1ZGqhKrkxZs/Ft4Q5EWAlaMB7Ktg8S85CuMnRWYCYLkFdWhfIHemeH9TMEN
QeTPv37KcaoBkkDYGMp3
=1iH6
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]