Quantcast
Channel: What's an example of a utility program that the env command could call? - Super User
Viewing all articles
Browse latest Browse all 3

Answer by grawity_u1686 for What's an example of a utility program that the env command could call?

$
0
0

A common use is to launch interpreters, by making use of the fact that env will search $PATH for the command it is told to launch. Since the shebang line requires an absolute path to be specified, and since the location of various interpreters (perl, bash, python) may vary a lot, it is common to use:

#!/usr/bin/env perl

instead of trying to guess whether it is /bin/perl, /usr/bin/perl, /usr/local/bin/perl, /usr/local/pkg/perl, /fileserver/usr/bin/perl, or /home/MrDaniel/usr/bin/perl on the user's system...

On the other hand, env is almost always in /usr/bin/env. (Except in cases when it isn't; some systems might use /bin/env, but that's a fairly rare occassion and only happens on non-Linux systems.)


Another use is to quickly clear the environment using the -i option. In legacy sysvinit initscripts, which are just shell scripts often launched directly by the sysadmin, it is necessary to make sure the admin's environment does not propagate to the started daemon. (For example, a rogue $TZ or $HOME might make things really confusing – especially with certain cron daemons.)

In this case, the initscript prepares a short environment and starts the daemon using something like:

env -i "PATH=/bin:/usr/bin""LANG=$system_locale" /usr/sbin/crond

Viewing all articles
Browse latest Browse all 3

Trending Articles