World Library  
Flag as Inappropriate
Email this Article

Env

Article Id: WHEBN0001927701
Reproduction Date:

Title: Env  
Author: World Heritage Encyclopedia
Language: English
Subject: Env (disambiguation), Hydrogen vehicle, LG enV3 (VX9200), Shebang (Unix), Standard Unix programs
Collection: Environment Variables, Standard Unix Programs, Unix Sus2008 Utilities
Publisher: World Heritage Encyclopedia
Publication
Date:
 

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

To print out a list of all environment variables, simply run env without any arguments:

env

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

Note that this use of env is often unnecessary since most shells support setting environment variables in front of a command:

DISPLAY=foo.bar:1.0 xcalc

env may also be used in the hashbang line of a script to allow the interpreter to be looked up via the PATH. For example, 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

External links

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.