why do shebangs contain complete paths?

Why do scripts' shebang lines contain something like:

#!/bin/sh

and not (say):

#!sh

?

No real reason.  The latter would be better.  shebang lines are not specified in POSIX, at all.  There is nothing stopping a Unix vendor from defining a system PATH (indeed, it's apparently supposed to be via getconf("PATH") in general) which is searched for unqualified interpreter names in shebang lines.  Just document it in the system manual, please.  The real reason it hasn't happened is that nothing has happened in Unix for 25 years.

Before you say "but the linux kernel executes shebangs, and the kernel can't just go calling getconf() and such", any such distinction between kernel and userspace is, from a Unix point of view, an internal implementation matter, and thus no excuse for anything.  The system, as a whole, should sort things out, and if the system spec were to say that unqualified shebang lines shall be interpreted according to the PATH from getconf(), then that is how the system would be.

In addition, and separately, POSIX does not say anything about "/bin/sh" existing (well, it does contain a reminder that it need not exist).  There is a "sh" utility, but POSIX doesn't say in /bin.


Comments

Popular posts from this blog

the persistent idiocy of "privileged ports" on Unix

google is giving more and more 500 errors

Guernsey Waste in incorrect bag-rejection horror May 6th, 2024