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!
== Design == In all [[Unix]] and [[Unix-like]] systems, as well as on Windows, each process has its own separate set of environment [[Variable (programming)|variable]]s. By default, when a process is created, it inherits a duplicate [[run-time environment]] of its parent process, except for explicit changes made by the parent when it creates the child. At the [[Application programming interface|API]] level, these changes must be done between running <code>fork</code> and <code>exec</code>. Alternatively, from [[command shell]]s such as [[Bash (Unix shell)|bash]], a user can change environment variables for a particular command invocation by indirectly invoking it via <code>[[env]]</code> or using the <code>ENVIRONMENT_VARIABLE=VALUE <command></code> notation. A running program can access the values of environment variables for configuration purposes. [[Shell script]]s and [[Batch file|batch files]] use environment variables to communicate data and preferences to [[child process]]es. They can also be used to store temporary values for reference later in a shell script. However, in Unix, [[#Unix|non-exported variables]] are preferred for this as they do not leak outside the process. In Unix, an environment variable that is changed in a script or compiled program will only affect that process and possibly child processes. The parent process and any unrelated processes will not be affected. Similarly, changing or removing a variable's value inside a [[DOS]] or Windows batch file will change the variable for the duration of <code>[[COMMAND.COM]]</code>or <code>[[CMD.EXE]]</code>'s existence, respectively. In Unix, the environment variables are normally initialized during system startup by the system [[init]] [[startup script]]s, and hence inherited by all other processes in the system. Users can, and often do, augment them in the profile script for the command shell they are using. In Microsoft Windows, each environment variable's default value is stored in the [[Windows Registry]] or set in the <code>[[AUTOEXEC.BAT]]</code> file. On [[Unix]], a [[setuid]] program is given an environment chosen by its caller, but it runs with different authority from its caller. The [[dynamic linker]] will usually load code from locations specified by the environment variables <code>$LD_LIBRARY_PATH</code> and <code>$LD_PRELOAD</code> and run it with the process's authority. If a setuid program did this, it would be insecure, because its caller could get it to run arbitrary code and hence misuse its authority. For this reason, [[libc]] unsets these environment variables at startup in a setuid process. setuid programs usually unset unknown environment variables and check others or set them to reasonable values. In general, the collection of environment variables function as an [[associative array]] where both the keys and values are strings. The interpretation of characters in either string differs among systems. When data structures such as lists need to be represented, it is common to use a colon (common on Unix and Unix-like) or semicolon-delineated (common on Windows and DOS) list.
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)