help-bash
[Top][All Lists]
Advanced

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

Re: Usr/bin/env


From: Tapani Tarvainen
Subject: Re: Usr/bin/env
Date: Sat, 14 Aug 2021 16:45:08 +0300

On Sat, Aug 14, 2021 at 01:42:42PM +0200, Julius Hamilton (julkhami@gmail.com) 
wrote:

> At the top of a script I see "#!/usr/bin/env sh".
> 
> I was curious, what software system is this a part of? Bash, Linux, or
> Unix? I.e., I assume the shebang is common to various shell languages,
> bash, zsh, etc.

Actually, no - it's lower level, operating system's program loader
mechanism that tells it which interpreter to load, and it's common to
all Unix-like operatins systems. The interpreter called does not need
to know about it.

> "Sh" is a shell chosen. But if I wanted to know more about
> this directory, "/usr/bin/env", what is this concept's original location?
> Does this filesystem structure go back to Unix?

Yes. More specifically, BSD version 4.4. Since then it has been
adopted by just about all Unix-like operating systems, including
Gnu/Linux and MacOS, and standardized by POSIX.

> Or is Unix no longer commonly used so I should turn to the Linux
> documentation?

"Unix" is not a single entity - if you are using some version of it,
refer to its specific documentation. Ditto for Linux (or for common
Linux distributions, Gnu documentation). Or go for portability and
look up what POSIX says.

Incidentally, I see very little point in "#!/usr/bin/env sh", as "sh"
is pretty much guaranteed to be in /bin (if it isn't, then chances are
env isn't in /usr/bin either). The only real use case is when you have
several versions of sh in your system and /bin/sh isn't the one you
want, although even then just specifying the explicit path might be
better (env will pick whichever is first in PATH).

But "#!/usr/bin/env bash" could make sense also if you want your
script to be portable to non-Linux systems, where bash may be in a
nonstandard location.

And of course env is useful in its original purpose of setting up
environment variables for the interpreter called.

-- 
Tapani Tarvainen



reply via email to

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