Shell – Does “sh” have to be in the “/bin” directory

linuxposixshell

I have read that POSIX compliant operating systems (for example: Linux) must have the sh shell.

But is it required for sh to be in the /bin directory, or can it be in any directory?

Best Answer

POSIX only mandates the /dev and /tmp directories to exist, and the /dev/null, /dev/tty, and /dev/console files. The standard utilities must exist, but there is no particular location specified. There may not be a /bin at all, and if there is it may not contain a sh, and if it does that may not be a POSIX sh.

You can get a valid PATH variable that includes the POSIX tools, including sh, with the getconf command:

$ PATH=$(getconf PATH)
$ sh

This can be useful on, for example, Solaris, where the default sh is not POSIX-compatible, but a compliant sh is provided and accessible in that way (because Solaris is a certified Unix). getconf PATH will include /usr/xpg4/bin at the front, which contains POSIX sh and a number of other required tools (including useless ones like cd).

Related Question