Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Environment variable
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assignment: Unix === The commands <code>env</code> and <code>set</code> can be used to set environment variables and are often incorporated directly into the shell. The following commands can also be used, but are often dependent on a certain shell. ''VARIABLE''=''value'' # (there must be no spaces around the equals sign) export ''VARIABLE'' # for [[Bourne shell|Bourne]] and related shells export ''VARIABLE''=''value'' # for [[KornShell|ksh]], [[Bash (Unix shell)|bash]], and related shells setenv ''VARIABLE'' ''value'' # for [[C shell|csh]] and related shells A few simple principles govern how environment variables achieve their effect. Environment variables are local to the process in which they were set. If two shell processes are spawned and the value of an environment variable is changed in one, that change will not be seen by the other. When a child process is created, it inherits all the environment variables and their values from the parent process. Usually, when a program calls another program, it first creates a child process by [[fork (system call)|fork]]ing, then the child adjusts the environment as needed and lastly the child [[exec (system call)|replaces]] itself with the program to be called. This procedure gives the calling program control over the environment of the called program. In Unix shells, variables may be assigned without the '''<code>export</code>''' keyword. Variables defined in this way are displayed by the '''<code>set</code>''' command, but are ''not'' true environment variables, as they are stored only by the shell and are unknown to all other processes. The <code>printenv</code> command will not display them, and child processes do not inherit them. ''VARIABLE''=''value'' The prefix syntax exports a "true" environment variable to a child process without affecting the current process:<ref name="ClassicShS"/> ''VARIABLE''=''value'' program_name [arguments] The persistence of an environment variable can be session-wide or system-wide. '''<code>unset</code>''' is a builtin command implemented by both the [[Bourne shell]] family (<code>sh</code>, <code>ksh</code>, <code>bash</code>, etc.) and the [[C shell]] family (csh, tcsh, etc.) of [[Unix shell|Unix command line shell]]s. It unsets a shell variable, removing it from memory and the shell's exported environment. It is implemented as a [[shell builtin]], because it directly manipulates the internals of the shell.<ref name="OG_unset"/><ref name="Bash_unset"/> Read-only shell variables cannot be unset. If one tries to unset a read-only variable, the <code>unset</code> command will print an error message and return a non-zero exit code.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)