Env
1927701
218938134
2008-06-12T21:08:41Z
Calvin 1998
5642846
Reverted edits by [[Special:Contributions/24.195.111.186|24.195.111.186]] to last version by DumZiBoT (using [[WP:HG|Huggle]])
{{lowercase|title=env}}{{otheruses}}
'''<tt>env</tt>''' is a [[Unix shell|shell]] [[command (computing)|command]] for [[Unix]] and [[Unix-like]] [[operating system]]s. It is used to either print a list of [[environment variable]]s or run another utility in an altered environment without having to modify the currently existing environment. Using <tt>env</tt>, variables may be added or removed, and the values of existing variables may be changed.
In practice, <tt>env</tt> has another common use. It is often used by [[shell script]]s to launch the correct [[Interpreter (computing)|interpreter]]. In this usage, the environment is typically not changed.
==Examples==
To clear the environment for a new shell:
<source lang="bash">
env - /bin/sh
</source>
To launch the [[X Window]] application [[xcalc]] and have it appear on a different display:
<source lang="bash">
env DISPLAY=foo.bar:1.0 xcalc
</source>
Here is the code of a very simple [[Python (programming language)|Python]] script:
<source lang="bash">
#!/usr/bin/env python
print "Hello World."
</source>
In this example, <tt>/usr/bin/env</tt> is the full [[Path (computing)|path]] of the <tt>env</tt> command. The environment is not altered.
Note that it is possible to specify the interpreter without using <tt>env</tt>, by giving the full path of the <tt>python</tt> interpreter. A problem with that approach is that on different computer systems, the exact path may be different. By instead using <tt>env</tt> as in the example, the interpreter is searched for and located at the time the script is run. This makes the script more [[Porting|portable]], but also increases the risk that the wrong interpreter is selected because it searches for a match in every directory on the executable search path.
==External links==
*[http://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html env] -- manual page from [[GNU]] [[coreutils]].
*{{man|1|env|Linux| run a program in a modified environment}}
{{unix commands}}
[[Category:Unix software]]
[[it:Env (Unix)]]
[[ja:Env]]
[[pl:Env]]
[[ru:Env]]