Flux rss

Environment variables

Environment variables

An environment variable is a dynamic value loaded into the memory that can be used by several processes operating simultaneously. On most operating systems, the location of some libraries or of the main system executables may be different depending on the installation.

It is therefore possible, from a given programme, to refer to a location based on the environment variables that define these data.

In Windows

In Windows, the environment variables are placed between the "%" character. Thus to display the value of an environment variable, simply type following type of command:

echo %NAME_OF_THE_VARIABLE%

Here is a non-exhaustive list of the main environment variables on Windows systems:

Environment variable Description
%APPDATA% Returns an access path to the default directory containing the user programmes (by default: C:\Program Files\.
%CMDCMDLINE% Returns the exact command used to access the command interpreter (cmd.exe).
%COMPUTERNAME% Returns the name attributed to the computer.
%DATE% Returns the day's date.
%ERRORLEVEL% Contains the error code of the latest command used.
%HOMEDRIVE% Contains the letter of the drive on which the current user's directory is located.
%HOMEDRIVE% Contains the letter of the drive on which the current user's directory is located.
%HOMEPATH% Contains the full access path to the current user's directory.
%NUMBER_OF_PROCESSOR% Contains the number of processors present on the system.
%OS% Contains a chain of characters describing the operating system installed. Note that Windows 2000 is identified as WINDOWS_NT.
%PATH% Specifies the access path to the system's main executables.
%PATHEXT% Describes the extensions that the system considers to be executable.
%PROCESSOR_ARCHITECTURE% Describes the architecture of the processor (x86 for Intel machines, IA64 for RISC architectures).
%RANDOM% Returns an integer between 0 and 32167 chosen at random by the system.
%SYSTEMDRIVE% Contains the letter of the drive on which the system is located (generally C:).
%SYSTEMROOT% Contains the access path to the system's root directory.
%TEMP% Contains the temporary directory access path for the applications.
%TMP% Contains the temporary directory access path for the applications.
%TIME% Returns the day's date.
%USERDOMAIN% Contains the domain to which the current account belongs.
%USERNAME% Contains the user name corresponding to the current account.
%USERPROFILE% Contains the location of the current account user profile.
%WINDIR% Contains the access path to the system's directory (generally C:\WINDOWS or C:\WINNT).

In Windows, the set command allows creation, modification and display of the environment variables. However, changes are made only in the session in progress.

To display a variable, the following command is used:

set VariableName 

To create a variable, the following command is used:

set VariableName=value

To delete a variable, the following command is used:

set VariableName=
It is possible to use any character as a value, including spaces. However, to be able to use special characters (<, >, |, & or ^), simply place the (^) escape character in front of them or quotation marks around them, which will then be part of the value since all characters following the = sign are taken into account. For example, to define "black&white" as the value:
set colour=black^&white
	or
set varname="new&name"

In UNIX

In UNIX systems, the environment variables are preceded by the "$" character and placed between braces, even though the braces are not compulsory. Given the variety in UNIX systems (particularly the different Linux distributions), the environment variables Thus to display the value of an environment variable, simply type one of the following commands:

echo $VARIABLE
echo ${VARIABLE}

Here is a non-exhaustive list of the main environment variables on UNIX systems:

Environment variable Description
$ARCH Contains the description of the machine's architecture.
$DISPLAY Contains the ID of the display terminal to be used in the window administrator (X11).
$HOME Returns the access path to the current user's directory.
$HOST Returns the computer name.
$LANG Returns the default language code.
$PATH Returns a list of access paths to directories containing executables, separated by semi-colons.
$PRINTER Contains the name of the default printer.
$SHELL Indicates the path of the command interpreter used.
$USER Returns the ID of the current user.


Last update on Thursday October 16, 2008 02:43:19 PM.
This document entitled « Environment variables » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the licence, as this note appears clearly.
[VBA/VB6] My Documents + Environment Variables [VBA/VB6] My Documents + Environment Variables With VBA With VB6 Environment Functions Windows Variables Getting started As displayed in Windows Explorer, the My Documents folder appears to be in the root, but it is not the case. It... en.kioskea.net/faq/sujet-951-vba-vb6-my-documents-environment-variables
Current directory Hello, I need help on creating a batch file that will save the current drive and directory in the environment variable _currentdirectory. en.kioskea.net/forum/affich-14485-current-directory
Excel wont open on MAC Hello, MAC doesn't support excel. Is there any way that i can open my excel attachment on MAC. This excel spreadsheet has various tab and i want to work on them in MAC environment. Please help. Thanks, -Dinesh en.kioskea.net/forum/affich-20155-excel-wont-open-on-mac
How to read a RealMedia Variable (RMVB) Bitrate fileHow to read a RealMedia Variable (RMVB) Bitrate file What is a RMVB file? How to read a RealMedia Variable Bitrate file Convert a RealMedia File Using EO Video What is a RMVB file? RMVB is the acronym used for RealMedia Variable... en.kioskea.net/faq/sujet-232-how-to-read-a-realmedia-variable-rmvb-bitrate-file
Modifying a read-only variableModifying a read-only variable Solution 1 Solution 2 Solution 1 A variable declared as read-only can not be modified during outgoing process. But if the variable is exported in a child shell it may be modified. #!/bin/bash if [... en.kioskea.net/faq/sujet-944-modifying-a-read-only-variable
Swapping two variables without using a temp variableSwapping two variables without using a temp variable Using pointers Making use of a Macro Using pointers #include void change(int *,int*); int main () { int a=2,b=5; printf("Before : a=%d,b=%d\n",a,b); ... en.kioskea.net/faq/sujet-966-swapping-two-variables-without-using-a-temp-variable
[PHP/Mysql] Affectation d'une requête à variaHello, voici ma petite question, j'ai une petite requête qui ne peut me donner qu'une seule valeur de retour assuré. Donc je souhaitais affecter cette valeur à une variable sans passé par une boucle et tout le tsoin tsoin, j'ai donc... en.kioskea.net/forum/affich-321-php-mysql-affectation-d-une-requete-a-varia
Returning contents of last cell in rowHello, I am trying to write a macro that returns the data contents of the last cell in a row of data. I then need to declare the cell's data as a variable. So far, my code is this (from another online tutorial): Public Sub LastColumnInOneRow()... en.kioskea.net/forum/affich-27391-returning-contents-of-last-cell-in-row
Date to number format using macroHello, in a macro i have captured the date into a variable. i need to convert that date to a number format to used for further processing. thanks, en.kioskea.net/forum/affich-20178-date-to-number-format-using-macro
Download VLCVLC media player is a portable multimedia player for many video and audio formats (MPEG1, MPEG2, MPEG4, DivX, mp3, ogg, ...) as well as DVDs, VCDs, and various streaming protocols. This program can also be used as a server to stream in unicast or... en.kioskea.net/telecharger/telecharger-34-vlc
Download DB Designer Allows you to handle your databases the most efficient way. DBDesigner 4 is a visual database design system that integrates database design, modeling, creation and maintenance into a single, seamless environment. It combines a simple and clear... en.kioskea.net/telecharger/telecharger-273-db-designer
Download AVS DVD PlayerAVS DVD Player is an universal DVD, VIDEO & AUDIO Player: Supporting a very wide variety of video formats : apart from regular DVD (PAL, NTSC, VCD, SVCD) formats, also supported are: the entire range of MPEG4 (including DivX, XviD, etc.), MPEG1,... en.kioskea.net/telecharger/telecharger-80-avs-dvd-player
Networking - Client/Server Architecture Numerous applications run in a client/server environment, this means that client computers (computers forming part of the network) contact a server, generally a very powerful computer in terms of input/output, which provides services to the client... en.kioskea.net/cs/csintro.php3
Project management - Project stages In order to be managed in an atmosphere of quality, a project must pass through various phases, at the end of which milestones should be defined. Each stage is related to a deliverable and a validation based on a specific document. This allows... en.kioskea.net/projet/etapes-projet.php3
Networking - Mainframe The first computer networks were built around a central computer called a "mainframe". The mainframe is therfore a powerful central computer which controls user sessions at the various terminals that are connected to it. Thanks to this architecture... en.kioskea.net/cs/mainframe.php3