0% found this document useful (0 votes)
11 views2 pages

Environment Variabl

An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Environment Variabl

An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

An environment variable is a user-definable value that can affect the way

running processes will behave on a computer. Environment variables are part of the
environment in which a process runs. For example, a running process can query the value of
the TEMP environment variable to discover a suitable location to store temporary files, or the
HOME or USERPROFILE variable to find the directory structure owned by the user running
the process.

They were introduced in their modern form in 1979 with Version 7 Unix, so are included in
all Unix operating system flavors and variants from that point onward
including Linux and macOS. From PC DOS 2.0 in 1982, all succeeding Microsoft operating
systems, including Microsoft Windows, and OS/2 also have included them as a feature,
although with somewhat different syntax, usage and standard variable names.

Design
[edit]
In all Unix and Unix-like systems, as well as on Windows, each process has its own
separate set of environment variables. 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 API level, these changes must be done between
running fork and exec. Alternatively, from command shells such as bash, a user can
change environment variables for a particular command invocation by indirectly invoking it
via env or using the ENVIRONMENT_VARIABLE=VALUE <command> notation. A running program
can access the values of environment variables for configuration purposes.

Shell scripts and batch files use environment variables to communicate data and
preferences to child processes. They can also be used to store temporary values for
reference later in a shell script. However, in 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 COMMAND.COMor CMD.EXE's existence, respectively.

In Unix, the environment variables are normally initialized during system startup by the
system init startup scripts, 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 AUTOEXEC.BAT 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 $LD_LIBRARY_PATH and $LD_PRELOAD 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.

Syntax
[edit]
The variables can be used both in scripts and on the command line. They are usually
referenced by putting special symbols in front of or around the variable name.

It is conventional for environment-variable names to be chosen to be in all upper cases. In


programming code generally, this helps to distinguish environment variables from other
kinds of names in the code. Environment-variable names are case sensitive on Unix-like
operating systems but not on DOS, OS/2, and Windows.

You might also like