All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David A. Wheeler" <dwheeler@dwheeler.com>
To: Philip Pokorny <ppokorny@mindspring.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: Why /usr/bin/env in scripts
Date: Mon, 25 Apr 2005 13:45:19 -0400	[thread overview]
Message-ID: <426D2CAF.7080101@dwheeler.com> (raw)
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
>
> rather than what I'm more familiar with:
>
> #!/bin/bash

...

> So what am I missing?  Is this a portability aid?


Correct.  Bash gets installed in different places on different systems,
e.g., on OpenBSD bash is NOT in /bin or /usr/bin, but in /usr/local/bin.
Invoking "/bin/sh" on OpenBSD will _NOT_ get you bash, but a pdksh
variant that doesn't implement the bash capabilities some scripts require.
Using env this way an old trick; I don't know who originally came up 
with it.

Technically, even this isn't 100% portable.  Leading "#!" (shebang)
isn't implemented by a very few old systems (it's not in the Single User 
Spec,
though it was introduced between v7 and v8 of Unix). Also,
you can find one or two really obscure systems where env isn't in /usr/bin
(OpenServer 5 and a few really old Linux distributions).
But env is ONLY in /usr/bin for the *BSDs.
This version runs on 99.999% of the Linux/Unix systems, and takes
essentially zero effort to implement; "more portable" solutions are so much
more work that few people bother if they're writing shell scripts.

--- David A. Wheeler


      parent reply	other threads:[~2005-04-25 17:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-25  7:38 Why /usr/bin/env in scripts Philip Pokorny
2005-04-25  9:42 ` David Greaves
2005-04-25 17:45 ` David A. Wheeler [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=426D2CAF.7080101@dwheeler.com \
    --to=dwheeler@dwheeler.com \
    --cc=git@vger.kernel.org \
    --cc=ppokorny@mindspring.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.