* Why /usr/bin/env in scripts
@ 2005-04-25 7:38 Philip Pokorny
2005-04-25 9:42 ` David Greaves
2005-04-25 17:45 ` David A. Wheeler
0 siblings, 2 replies; 3+ messages in thread
From: Philip Pokorny @ 2005-04-25 7:38 UTC (permalink / raw)
To: Git Mailing List
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
I see that env can be used to alter the environment before running a
program, but that doesn't seem to be happening here.
In fact, on my system /usr/bin/env is a link to /bin/env...
So what am I missing? Is this a portability aid?
Thanks,
:v)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why /usr/bin/env in scripts
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
1 sibling, 0 replies; 3+ messages in thread
From: David Greaves @ 2005-04-25 9:42 UTC (permalink / raw)
To: Philip Pokorny; +Cc: Git Mailing List
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why /usr/bin/env in scripts
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
1 sibling, 0 replies; 3+ messages in thread
From: David A. Wheeler @ 2005-04-25 17:45 UTC (permalink / raw)
To: Philip Pokorny, Git Mailing List
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-04-25 17:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).