In Data-processing, the variable of environment are dynamic variables used by the various processes of an operating system (Windows, Unix… etc).
One also speaks about Variables of environment cgi for a Serveur HTTP.
Posting of the list of the variables of environment
On Windows
The order
set without any parameter makes it possible to list the majority of the variables of environment.
The variables %ERRORLEVEL%, %DATE%, %TIME%, %CD%, %RANDOM% are not posted by the order set (NB: the role of these variables is explained in the following paragraphs).
On Unix
the order
env without any parameter makes it possible to list the variables known as of environment.
-
the variable $? is not posted by the order env . That corresponds to the code return of the last order carried out.
In Shell usual of Unix/linux, the instruction
set makes it possible to post at the same time the variables of environment and the other variables.
Modification of a variable of environment
On Windows
To modify a variable of environment (attention, that goes only on the process in progress)
set path=%path%; c:\WINDOWS\System32\wbem
To modify a variable of environment in a permanent way it is necessary:
- To modify the autoexec.bat with the order set under Windows 98.
- To add or modify the key of register HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment or HKEY_CURENT_USER \ Environment \ under Windows 2000/xp/2003
It is also possible to modify the variables of environment under the system object of the control panel.
On Unix
To modify a variable of environment (attention, that goes only on the process in progress)
PATH=$PATH:. / - If the process in progress launches another process (via a call to the function '' fork ''), this new process will not inherit not the variables of environment except if they are exportable (order export ).
- the order env makes it possible to launch a process by positioning values of environment. Example:
env LD_LIBRARY_PATH=/var/lib ./configure
To modify a variable of environment in a permanent way, one can add a line in his script ~/.bashrc to assign and export the variable. Here a minimal example of ~/.bashrc :
# Source total definitions
yew - F /etc/bashrc; then
. /etc/bashrc
fi
# To use specific aliases and functions
LANG=fr_CA.UTF8 export
Script ~/.bashrc is personal with the user.
It is carried out to each time one connects oneself (either directly or by HS) and to each time one opens a new console.
So that the assignment of the variable benefits all the users, one can add it in script /etc/profile (with the proviso of having the rights).
Variable of Windows environment
Parameters related to the user profile
%ALLUSERSPROFILE%
Indicate the repertory of the profile common to all the users.
Example of values:
`' C:\Documents and settings\All Users''
Caution: Not to confuse with the profile by defect
`' C:\Documents and settings\Default To use''
%APPDATA%
Example of values:
`' C:\Documents and settings\Dupont\Application Dated' '
It contains the application data of the connected user
%HOMEPATH%
Example of value
`' C:\Documents and settings\Dupont''
%USERNAME%
%USERNAME% contain the name of the user connected (example: Dupont).
%USERPROFILE%
%USERPROFILE% show the way of the repertory containing the hive HKEY_CURRENT_USER of the connected user (files NTUSER.DAT and NTUSER.INI)
%CD%
The variable %CD% is not posted by the order
set , it gives the way of the current directory.
%COMPUTERNAME%
The name of the computer contains
%ComSpec%
See variable environment positioned by the manager of session (smss.exe)
%DATE% and %TIME%
The variables %DATE% and %TIME% are not posted by the order
set . They give the date and the hour.
%ERRORLEVEL%
The variable %ERRORLEVEL% is not posted by the order
set , it gives the code return of the last order carried out. It is the equivalent of the variable $? of Unix.
It is an essential order to make Shell sophisticated under Windows (files of extension .BAT)
Two examples of code
yew errorlevel 2 goto no_such_file
IF ERRORLEVEL 2 SET CODE_ERREUR=2
See Syntax of the errorlevel in a batch
%FP_NO_HOST_CHECK%
See variable environment positioned by the manager of session (smss.exe)
%HOMEDRIVE%
Default value
C:
%LOGONSERVER% and %USERDOMAIN%
If the user is connected for a
field,
- %LOGONSERVER% indicates the name of the controller of field used for the authentification, preceded by `' \ \''. Example:
`' \ \ ctrl_dom''
- %USERDOMAIN% indicates the name of the
field
If the user is connected for an work group (workgroup),
- %LOGONSERVER% and indicates the same thing as %COMPUTERNAME%, preceded by `' \ \''. Example:
\ \ PCDupont
- %USERDOMAIN% indicates the same thing as %COMPUTERNAME%
%NUMBER_OF_PROCESSORS%
See variable environment positioned by the manager of session (smss.exe)
%OS%
See variable environment positioned by the manager of session (smss.exe)
%Path%
See
PATH
%PATHEXT%
See variable environment positioned by the manager of session (smss.exe)
Variable of environment whose name starts with PROCESSOR_*
For %PROCESSOR_ARCHITECTURE%, %PROCESSOR_IDENTIFIER%, %PROCESSOR_LEVEL%, %PROCESSOR_REVISION%, to see variable environment positioned by the manager of session (smss.exe)
%ProgramFiles%
This variable of environment shows the way of the repertory of the programs installed of Windows.
Its default value is:
`' C:\Program Files''
%PROMPT%
Its default value is
$P$G
%RANDOM%
The variable %RANDOM% is not posted by the order
set , it generates a number Pseudo-aléatoire.
%SESSIONNAME%
Example of value
Comfort
%SystemDrive%
Default value
`' C: ''
%SystemRoot%
See
%SystemRoot%
2 temporary file directories
%TMP% and %TEMP%
%WinDir%
Analog with %systemRoot%
%JAVA_HOME%
to see variable environment positioned by the manager of session (smss.exe)
------------------------------------------------------
Variable of Unix environment (or linux)
Example of variables of environment under Unix
August 1st
$? : the code return
The variable
$? is not posted by the order
env . That corresponds to the code return of the last order carried out.
$#: the number of arguments
$# indicates the number of arguments.
$_
The variable
$ _ indicates the name of the last argument treated by the last order.
CFLAGS and CXXFLAGS for the compilation
See
CFLAGS
Repertories $HOME, $PWD, $OLDPWD
- the variable $HOME contains the absolute way towards the personal repertory of the connected user.
- the variable $PWD contains the absolute way towards the current directory (allows to know where one is in the tree structure).
- the variable $OLDPWD contains the absolute way towards the preceding current directory (allows to know from where one comes).
$LANG and $LANGUAGE
The variable $LANG is used by the various programs to determine the language of the messages to post.
For example:
a@localhost ~] LANG=fr ls FF
ls: FF: No file or repertory of this type
a@localhost ~] LANG=en ls FF
ls: FF: No such file gold directory
These various translations are in the files .mo sub-directories of /usr/share/locale .
The variable $LANG is used also for Vim to determine the encoding to use. Let us suppose the file .txt containing like only line “” encodée in UTF-8. To publish this file with VI in the konsole it is necessary to pose “LANG=fr.UTF8 export” and to make sure that the encoding of the konsole is fixed at UTF-8 (Configuration->Encodage).
If the encoding of the konsole is fixed at ISO 8859-1, vim will post “été”. If the variable $LANG does not specify the encoding Utf-8, for example $LANG=fr, but that the encoding of the konsole is with UTF-8, vim will post “be”, but the position of the cursor will not follow well. Indeed, although the konsole posts three characters, vim count five of them (try to go at the end of the line with $, the cursor will go too far).
$LD_LIBRARY_PATH
The variable $LD_LIBRARY_PATH contains a list of repertory, separated by: , where the libraries are which are not installed in the repertories by defect (/usr/lib and /usr/local/lib do not have to be indicated in $LD_LIBRARY_PATH).
During the execution of an application dynamically dependant on a library, the library is initially required in the repertories by defect, then in the repertories enumerated in the variable $LD_LIBRARY_PATH in order of appearance.
If the library is not found, an error message similar to this one will be launched during the execution:
le_nom_du_binaire: error while loading shared libraries: libXX.so.0: open boat shared object file: No such file gold directory
X11
Example of value
: 0.0 - the first figure is the number of waiter X11
- the second is the number of terminal
Example of value
Xterm
Variables of environment related to GNOME
COLORTERM
Example of value
- gnome-terminal
$DESKTOP_SESSION
Example of value:
default
$DESKTOP_STARTUP_ID
To supplement
$GDM_XSERVER_LOCATION and $GDMSESSION
See GNOME Display To manage
$GNOME_DESKTOP_SESSION
Example of value
Default
$GNOME_KEYRING_SOCKET
Example of value
/tmp/keyring-24TGGU/socket
Variables of environment related to KDE
To supplement
GTK
$LC_ALL
To supplement
HS
- $SSH_AGENT
- $SSH_AUTH_SOCK
$LOGNAME, $USER and $USERNAME
To supplement
$SHELL
$SHELL indicates the Interpréteur Shell used by defect. The usual value under linux is
/bin/ Bash
On certain versions of Unix, it is more primitive Shell which is installed by defect.
To have the list of Shell under Unix, to see : category: Shell Unix.
Other variables
- $PATH
- $SHLVL , the level of init, to see init of Unix System V
- $LS_COLORS
- $SESSION_MANAGER
- $XAUTHORITY
- $WINDOWID
Variables other than those of environment
For the internal variables, to see Variable
There exist variables which do not form part of the variables of environment. For example, on the version Sarge of the distribution Debian, there can be:
- Variable related to Shell
- $BASH , $BASH_VERSINFO , $BASH_VERSION
- $HISTFILE , $HISTFILESIZE and $HISTSIZE : parameters of the history of the orders Shell
See too
Related articles