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
> 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
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.
> 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.
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
> 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]
Mark, I think this is a good summary! Thanks to you and all others
who have answered in this thread!