Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

/bin/env standard location?

16 views
Skip to first unread message

Martin Ramsch

unread,
Oct 14, 1999, 3:00:00 AM10/14/99
to
Hi all,

I wonder if there is a standard location for the env command that is
the same in all or as many as possible flavours of Unix (SysV style,
BSD style, SunOs, Solaris, Linux ...)?

Should /bin/env always exist?

Or are there systems that don't even have the env command at all?


Motivation:

I'd like to start my perl scripts using

#! /bin/env perl

because this way the perl interpreter should be searched in the
current command PATH and I don't have to hard-code the path to the
perl binary.

Regards,
Martin
--
Martin Ramsch <m.ra...@computer.org> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=5244 5EF3 B0B1 3826 E4EC 8058 7B31 3AD7

Christian Weisgerber

unread,
Oct 14, 1999, 3:00:00 AM10/14/99
to
Martin Ramsch <m.ra...@computer.org> wrote:

> I wonder if there is a standard location for the env command that is
> the same in all or as many as possible flavours of Unix (SysV style,
> BSD style, SunOs, Solaris, Linux ...)?
>
> Should /bin/env always exist?

FreeBSD: /usr/bin/env
Red Hat Linux: /usr/bin/env

--
Christian "naddy" Weisgerber na...@mips.rhein-neckar.de

Joe Moore

unread,
Oct 14, 1999, 3:00:00 AM10/14/99
to
In article <slrn80bk3o....@melian.forwiss.uni-passau.de>,

Martin Ramsch <m.ra...@computer.org> wrote:
>
>Motivation:
>
>I'd like to start my perl scripts using
>
> #! /bin/env perl
>
>because this way the perl interpreter should be searched in the
>current command PATH and I don't have to hard-code the path to the
>perl binary.

On most systems, either /bin is a link to /usr/bin, or it has a /bin/env.

However,

I don't think that would work. When the kernel executes the script (via
the #! feature) it uses the argument as the program to execute. (and I think
the name of the file as the last command line arguemnt.

So you would effectively be running "/bin/env perl foo.pl" which I don't
think would do what you want.

There might be a way to do it... by
untested:#!/bin/sh -c eval `/bin/env perl`
But I doubt it -- You might only be allowed one option. It'd be better to
install a link to perl in some standard path and refer to that.

Check for the link during installation, and update the path if neccessary.

--Joe
--
IBM's vision is apparently to make IBM hardware "scream with Microsoft
software" --The Register, http://www.theregister.co.uk/990927-000003.html

I have visions of screaming with (at and about) Microsoft software, too.

Christian Weisgerber

unread,
Oct 15, 1999, 3:00:00 AM10/15/99
to
Joe Moore <jmo...@rios85.sdrc.com> wrote:

> On most systems, either /bin is a link to /usr/bin, or it has a /bin/env.

Rather: ... or it has /usr/bin/env.

> So you would effectively be running "/bin/env perl foo.pl" which I don't
> think would do what you want.

Yes, it does. Clever idea, actually.

Owen M. Astley

unread,
Oct 15, 1999, 3:00:00 AM10/15/99
to
Attributed to Martin Ramsch <m.ra...@computer.org>:
> Should /bin/env always exist?

>
> Motivation:
>
> I'd like to start my perl scripts using
>
> #! /bin/env perl
>
> because this way the perl interpreter should be searched in the
> current command PATH and I don't have to hard-code the path to the
> perl binary.

Neat idea. Another idea appears to be (snipped from the top of weblint):

: # use perl -*- mode: Perl; -*-
eval 'exec perl -S $0 "$@"'
if $runnning_under_some_shell;

Owen


Mark Wooding

unread,
Oct 19, 1999, 3:00:00 AM10/19/99
to
Martin Ramsch <m.ra...@computer.org> wrote:

> Christian Weisgerber wrote that both FreeBSD and Red Hat Linux have
> /usr/bin/env,

Neither FreeBSD nor Redhat has /bin/env. Debian GNU/Linux also has
/usr/bin/env and not /bin/env. However, note that Solaris, Digital Unix
and IRIX at least have both /bin/env and /usr/bin/env. Digital Unix
also appears to have /usr/ucb/env for some reason, and IRIX has
/sbin/env.

> My current impression is that I should use /bin/env ...

I think the available evidence suggests that:

* /bin/env doesn't work;
* /usr/bin/env seems to work on most platforms; and
* Autoconf is a better solution to this problem.

-- [mdw]

Martin Ramsch

unread,
Oct 23, 1999, 3:00:00 AM10/23/99
to
On 19 Oct 1999 10:28:48 GMT,

Mark Wooding <m...@catbert.ebi.ac.uk> wrote:
>I think the available evidence suggests that:
>
> * /bin/env doesn't work;
> * /usr/bin/env seems to work on most platforms; and
> * Autoconf is a better solution to this problem.

Mark, I think this is a good summary! Thanks to you and all others
who have answered in this thread!

0 new messages