env
env is a shell command for Unix and Unix-like operating systems. It is used to either print a list of environment variables or run another utility in an altered environment without having to modify the currently existing environment. Using env, variables may be added or removed, and existing variables may be changed by assigning new values to them.
In practice, env has another common use. It is often used by shell scripts to launch the correct interpreter. In this usage, the environment is typically not changed.
Examples[edit]
To clear the environment (creating a new environment without any existing environment variables) for a new shell:
env -i /bin/sh
To launch the X application xcalc and have it appear on a different display:
env DISPLAY=foo.bar:1.0 xcalc
Here is the code of a very simple Python script:
#!/usr/bin/env python2
print "Hello World."
In this example, /usr/bin/env is the full path of the env command. The environment is not altered.
Note that it is possible to specify the interpreter without using env, by giving the full path of the python interpreter. A problem with that approach is that on different computer systems, the exact path may be different. By instead using env as in the example, the interpreter is searched for and located at the time the script is run. This makes the script more 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. It also suffers from the same problem in that the path to the env binary may also be different on a per-machine basis.
See also[edit]
External links[edit]
- The Single UNIX® Specification, Issue 7 from The Open Group : set the environment for command invocation – Commands & Utilities Reference,
- env -- manual page from GNU coreutils.
- OpenBSD General Commands Manual : run a program in a modified environment –
source - https://en.wikipedia.org/wiki/Env
'System > Linux' 카테고리의 다른 글
linux - dnf broken (0) | 2016.12.04 |
---|---|
fedora - 한영전환키 등록 화면 in fedora 23 (0) | 2015.12.30 |
linux - kmod vs akmod (0) | 2015.07.05 |
linux - history clear (0) | 2015.07.03 |
linux - What is the difference between reboot , init 6 and shutdown -r now? (0) | 2015.06.27 |