git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Why /usr/bin/env in scripts

From
David Greaves <david@dgreaves.com>
Date
Apr 25, 2005, 09:42 UTC
Message-ID
<426CBB95.9040203@dgreaves.com>
In-Reply-To
<426C9E63.4050907@mindspring.com>
Philip Pokorny wrote:
> I notice that the first line of the pasky shell scripts is
> 
> #!/usr/bin/env bash
> So what am I missing?  Is this a portability aid?
man env:

The first remaining argument specifies the program name to invoke; it is searched for according to the `PATH' environment variable. Any remaining arguments are passed as arguments to that program.

It's a trick to do a PATH search for a script interpreter rather than hard coding the path. Now all we have to do is make sure every distro on the planet has /usr/bin/env - and they do.

David
Previous: Philip PokornyNext: David A. Wheeler
Message 2 of 3 in “Why /usr/bin/env in scripts”
  1. Philip PokornyApr 25, 2005
  2. David GreavesApr 25, 2005
  3. David A. WheelerApr 25, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.