Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.

They can be said in some sense to create the operating environment in which a process runs. For example, an environment variable with a standard name can designate the location that a particular computer system uses to store temporary files – this may vary from one computer system to another. A process which invokes the environment variable by (standard) name can be sure that it is storing temporary information in a directory (folder) that exists and is expected to have sufficient space.

Contents

Synopsis [link]

In all Unix and Unix-like systems, each process has its own separate set of environment variables. By default, when a process is created, it inherits a duplicate environment of its parent process, except for explicit changes made by the parent when it creates the child. At 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. All Unix operating system flavors, MS-DOS, and Microsoft Windows have environment variables; however, they do not all use the same variable names. A running program can access the values of environment variables for configuration purposes.

Examples of environment variables include:

  • PATH - lists directories the shell searches, for the commands the user may type without having to provide the full path.
  • HOME (Unix-like) and USERPROFILE (Microsoft Windows) - indicate where a user's home directory is located in the file system.
  • HOME/{.AppName} (Unix-like) and APPDATA\{DeveloperName\AppName} (Microsoft Windows) - for storing application settings. Many open source programs incorrectly use USERPROFILE for application settings in Windows - USERPROFILE should only be used in dialogs that allow user to choose between paths like Documents/Pictures/Downloads/Music, for programmatic purposes APPDATA (roaming), LOCALAPPDATA or PROGRAMDATA (shared between users) is used.
  • TERM (Unix-like) - specifies the type of computer terminal or terminal emulator being used (e.g., vt100 or dumb).
  • PS1 (Unix-like) - specifies how the prompt is displayed in the Bourne shell and variants.
  • MAIL (Unix-like) - used to indicate where a user's mail is to be found.
  • TEMP - location where processes can store temporary files

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, other variables are usually used for this.

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. In MS-DOS, changing or removing a variable's value inside a BATCH file will change the variable for the duration of command.com's existence.

In Unix, the environment variables are normally initialized during system startup by the system init 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.

Getting and setting environment variables [link]

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. For instance, to display the user home directory, in most scripting environments, the user has to type:

<source lang="bash"> echo $HOME </source>

On DOS, OS/2 or Windows systems, the user has to type this:

<source lang="dos"> echo %HOME% </source>

In Windows PowerShell, the user has to type this:

<source lang="powershell"> Write-Output $HOME </source>

Unix [link]

The commands env, set, and printenv display all environment variables and their values. env and set are also used to set environment variables and are often incorporated directly into the shell. printenv can also be used to print a single variable by giving that variable name as the sole argument to the command.

In Unix, the following commands can also be used, but are often dependent on a certain shell.

export VARIABLE=value  # for Bourne, bash, and related shells
setenv VARIABLE value  # for csh and related shells

Working principles of environment variables [link]

A few simple principles govern how environment variables BY INSTALLING, achieve their effect.

Local to process [link]

Environment variables are local to the process in which they were set. That means that if we spawn two shell processes and change the value of an environment variable in one, that change will not be seen by the other.

Inheritance [link]

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 forking, then the child adjusts the environment as needed and lastly the child replaces itself with the program to be called. This procedure gives the calling program control over the environment of the called program.

Case-sensitive [link]

In Unix and Unix-like systems the names of environment variables are case-sensitive.

Persistence [link]

Environment variables persistence can be session-wide or system-wide.

DOS, OS/2 and Windows (Command Prompt) [link]

In DOS, OS/2 and Windows, the set command without any arguments displays all environment variables along with their values.

To set a variable to a particular value, use:

<source lang="dos"> set VARIABLE=value </source>

However, this is temporary. Permanent change to the environment variable can be achieved through editing the registry (not recommended for novices) and using the Windows Resource Kit application setx.exe. With the introduction of Windows Vista, the setx command became part of Windows.

Users of the Windows GUI can manipulate variables via <Control Panel:System:Advanced:Environment Variables>; through the Windows Registry this is done changing the values under HKCU\Environment (for user specific variables) and HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment (for System variables).

To set a variable whose name is in another variable, you can do:

<source lang="dos"> set %VARNAME%=value </source>

This feature allows certain interesting applications. For example, you may create a uni-dimensional array of elements (vector) this way:

<source lang="dos"> set VECTOR[%I%]=value of element subscript %I%

MkVec

set VECNAME=%1 set i=0

loop
   shift
   if "%1" == "" goto exitloop
   set /a i+=1
   set %VECNAME%[%i%]=%1
   goto loop
exitloop

exit /B %i%

call :MkVec DOWNAME=Monday Tuesday Wednesday Thursday Friday Saturday Sunday </source>

To see the current value of a particular variable, use:

<source lang="dos"> echo %VARIABLE% </source>

or

<source lang="dos"> set VARIABLE </source>

Note: Please take note that doing so will print out all variables beginning with 'VARIABLE'. Another example is:

<source lang="dos"> C:\> set p Path=c:\.. .. PATHEXT=.COM;.EXE;.BAT; PROCESSOR_ARCHITECTURE=.. .. PROCESSOR_IDENTIFIER=x8.. PROCESSOR_LEVEL=6.. PROCESSOR_REVISION=1706.. ProgramFiles=C:\Program.. . PROMPT=$P$G </source>

To see the value of an array element a double expansion is required: one for the subscript value and an additional expansion for the array element. This may be achieved via Delayed !VARIABLE! Expansion this way:

set DOW=value of Day of Week (1..7)
echo !DOWNAME[%DOW%]!

To delete a variable, the following command is used: <source lang="dos"> set VARIABLE= </source>

Windows PowerShell [link]

To set a system variable:

<source lang="powershell"> Set-Variable -name VARIABLE -value value $VARIABLE = value # alternate form of Set-Variable </source>

Case-insensitivity [link]

In Windows the names of environment variables are case-insensitive.

Unexported variables [link]

In Unix shells, variables may be assigned without the export keyword. Variables defined in this way are displayed by the set command, but are not true environment variables, as they are stored only by the shell and not recognized by the kernel. The printenv command will not display them, and child processes do not inherit them.

VARIABLE=value

However, if used in front of a program to run, the variables will be exported to the environment and thus appear as real environment variables to the program:

VARIABLE=value program_name [arguments]

The tool that gives closest parallel in Windows is the SETLOCAL/ENDLOCAL commands that prevent variables from being set globally.[clarification needed]

Security [link]

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.

Common environment variables [link]

Examples of Unix environment variables [link]

$PATH

Contains a colon-separated list of directories that the shell searches for commands that do not contain a slash in their name (commands with slashes are interpreted as file names to execute, and the shell attempts to execute the files directly). It is equivalent to the Windows %PATH% variable. See: Path (computing).

$HOME

Contains the location of the user's home directory. Although the current user's home directory can also be found out through the C functions getpwuid and getuid, $HOME is often used for convenience in various shell scripts (and other contexts). Using the environment variable also gives the user the possibility to point to another directory.

$PWD

This variable points to the current directory. Equivalent to the output of the command pwd when called without arguments.

$DISPLAY

Contains the identifier for the display that X11 programs should use by default.

$LD_LIBRARY_PATH

On many Unix systems with a dynamic linker, contains a colon-separated list of directories that the dynamic linker should search for shared objects when building a process image after exec, before searching in any other directories.

$LANG, $LC_ALL, $LC_...

LANG is used to set to the default locale. For example, if the locale values are pt_BR, then the language is set to (Brazilian) Portuguese and Brazilian practice is used where relevant. Different aspects of localization are controlled by individual LC_-variables (LC_CTYPE, LC_COLLATE, LC_DATE etc.). LC_ALL can be used to force the same locale for all aspects.

$TZ

Refers to Time zone. It can be in several formats, either specifying the timezone itself or referencing a file (in /usr/share/zoneinfo).

Examples of DOS environment variables [link]

%COMSPEC%

This variable contains the full path to the command processor, command.com.

%PATH%

This variable contains a semicolon-delimited list of directories in which the command interpreter will search for executable files. Equivalent to the Unix $PATH variable (although note that PATH on Windows additionally performs the same task as LD_LIBRARY_PATH on Unix-like systems). Note that %PATH% can also be set like this PATH=c:\dos; where SET isn't required.

%TEMP% and %TMP%

These variables contain the path to the directory where temporary files should be stored.

Examples from Microsoft Windows [link]

Discrete value variables [link]

These variables generally expand to discrete values, such as the current working directory, the current date, or a random number. Some of these are true environment variables and will be expanded by all functions that handle environment variables. Others, like %CD% simply look like environment variables and will only be expanded by some functions and shells. They are not case sensitive.

%CD%

This variable points to the current directory. Equivalent to the output of the command cd when called without arguments.

%DATE%

This variable expands to the current date. The date is displayed according to the current user's date format preferences.

The following is a way of reformatting the date and time for use in file copies. The example assumes UK format of day month year and the time is set for a 24 hour clock.

<source lang="DOS"> @echo off echo %DATE% %TIME% for /F "tokens=1-3 delims=/" %%a in ("%DATE%") do set MTH=%%a& set DAY=%%b& set YR=%%c for /F "tokens=1-3 delims=:." %%a in ("%TIME%") do set HR=%%a& set MIN=%%b& set SEC=%%c if "%HR:~0,1%"==" " set HR=0%HR:~1,1% set MYDATE=%YR%%MTH%%DAY%-%HR%%MIN%%SEC% echo %MYDATE% </source>

%ERRORLEVEL%

This variable points to the current error level. If there was an error in the previous command, this is what you need to check against to find out about that.

%RANDOM%

This variable returns a random number between 0 and 32767.

%TIME%

This variable points to the current time. The time is displayed according to the current user's time format preferences.

System path variables [link]

These variables refer to locations of critical operating system resources, and as such generally are not user-dependent.

%AppData%

Contains the full path to the Application Data folder of the logged-in user. Does not work on Windows NT 4.0 SP6 UK.

%LOCALAPPDATA%

This variable is the temporary files of Applications. Its uses include storing of Desktop Themes, Windows Error Reporting, Caching and profiles of web browsers.

%ComSpec%

This variable contains the full path to the command processor; on Windows NT based operating systems this is cmd.exe, while on Windows 9x and ME it is the DOS command processor, COMMAND.COM.

%PATH%

This variable contains a semicolon-delimited (do not put spaces in between) list of directories in which the command interpreter will search for an executable file that matches the given command. Equivalent to the Unix $PATH variable.

%ProgramFiles%

This variable points to Program Files directory, which stores all the installed program of Windows and others. The default on English-language systems is C:\Program Files. In 64-bit editions of Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)% which defaults to C:\Program Files (x86) and %ProgramW6432% which defaults to C:\Program Files. The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit redirection).

%CommonProgramFiles%

This variable points to Common Files directory. The default is C:\Program Files\Common Files.

%SystemDrive%

The %SystemDrive% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the drive upon which the system folder was placed. Also see next item.

The value of %SystemDrive% is in most cases C:.

%SystemRoot%

The %SystemRoot% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the location of the system folder, including the drive and path.

The drive is the same as %SystemDrive% and the default path on a clean installation depends upon the version of the operating system. By default, on a clean installation:

  • Windows NT 5.1 (Windows XP) and newer versions use \WINDOWS
  • Windows NT 5.0 (Windows 2000), Windows NT 4.0 and Windows NT 3.1 use \WINNT
  • Windows NT 3.5x uses \WINNT35
  • Windows NT 4.0 Terminal Server use \WTSRV
%WinDir%

This variable points to the Windows directory (on Windows NT-based operating systems it is identical to the %SystemRoot% variable, above). If the System is on drive C: then the default values are:

Note that Windows NT 4 Terminal Server Edition by default installs to C:\WTSRV.

User management variables [link]

These variables store information related to resources and settings owned by various user profiles within the system. As a general rule, these variables do not refer to critical system resources or locations that are necessary for the OS to run.

%AllUsersProfile% (%PROGRAMDATA% for Windows Vista, Windows 7)

The %AllUsersProfile%(%PROGRAMDATA%) variable expands to the full path to the All Users profile directory. This profile contains resources and settings that are used by all system accounts. Shortcut links copied to the All Users' Start menu or Desktop folders will appear in every user's Start menu or Desktop, respectively.

%UserDomain%

The variable holds the name of the Workgroup or Windows Domain to which the current user belongs. The related variable, %LOGONSERVER%, holds the hostname of the server that authenticated the current user's logon credentials (name and password). For Home PCs, and PCs in a Workgroup, the authenticating server is usually the PC itself. For PCs in a Windows Domain, the authenticating server is a domain controller (a primary domain controller, or PDC, in Windows NT 4-based domains).

%UserProfile%

The %UserProfile% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the location of the current user's profile directory, in which is found that user's HKCU registry hive (NTUSER).

Users can also use the %USERNAME% variable to determine the active users login identification.

Windows GUI forced variable expansion [link]

In certain cases it is not possible to create file paths containing environment variables using the Windows GUI, and it is necessary to fight with the user interface to make things work as intended.

  • In Windows 7, a shortcut may not contain the variable %USERNAME% in unexpanded form. Trying to create shortcut to \\server\share\accounts\%USERNAME% or C:\users\%USERNAME% will be silently changed to replace %USERNAME% with the account name of the currently logged-in user, when the OK button is pressed on the shortcut properties.
    • This can only be overridden if the %USERNAME% variable is part of a parameter to some other program in the shortcut. For example, %SYSTEMROOT%\Explorer.exe C:\Users\%USERNAME% is not expanded when OK is clicked, but this shortcut is treated as unsafe and displays a warning when opened.
  • In Group Policy Management on Server 2008 R2, a profile folder can not be redirected to a custom folder hierarchy. For example, the desktop can not be redirected to \\server\share\accounts\%USERNAME%\custom\path\desktop. Upon pressing OK, this is silently changed to "Create a folder for each user in the root path" with the path \\server\share\accounts\ pointing to "\username\desktop".
    • This behavior can only be overridden if the path contains a variable or drive letter that is not currently resolvable at the time of editing the GPO. For example if a mapping for drive O: does not exist on the server, then the path O:\folder\%username%\CustomTarget is not expanded when OK is clicked.
  • A domain user account may not contain a profile path or home folder path containing an unexpanded %USERNAME% variable. Upon clicking OK, this is silently replaced with the user's account name.
    • This causes problems for new user creation that is performed by copying an existing user account, if there are additional folders listed after the username in the path. For a pre-existing account with a profile path of \server\share\accounts\DomainUser\profile the Microsoft Management Console doesn't know which part of the path contains the previous user's name and doesn't change the path during the copy, resulting in the new account pointing to the other account's profile/home paths. The profile/home paths must be manually re-edited to point to the correct location.

Default Values on Microsoft Windows [link]

Variable Windows XP Windows Vista/7
 %ALLUSERSPROFILE% and %PROGRAMDATA% C:\Documents and Settings\All Users C:\ProgramData
 %APPDATA% C:\Documents and Settings\{username}\Application Data C:\Users\{username}\AppData\Roaming
 %COMPUTERNAME% {computername} {computername}
 %COMMONPROGRAMFILES% C:\Program Files\Common Files C:\Program Files\Common Files
 %COMMONPROGRAMFILES(x86)% C:\Program Files (x86)\Common Files C:\Program Files (x86)\Common Files
 %COMSPEC% C:\Windows\System32\cmd.exe C:\Windows\System32\cmd.exe
 %HOMEDRIVE% C: C:
 %HOMEPATH% \Documents and Settings\{username} \Users\{username}
 %LOCALAPPDATA% C:\Users\{username}\AppData\Local
 %LOGONSERVER% \\{domain_logon_server} \\{domain_logon_server}
 %PATH% C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths} C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
 %PATHEXT% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc
 %PROGRAMDATA%  %SystemDrive%\ProgramData
 %PROGRAMFILES%  %SystemDrive%\Program Files  %SystemDrive%\Program Files
 %PROGRAMFILES(X86)%  %SystemDrive%\Program Files (x86) (only in 64-bit version)  %SystemDrive%\Program Files (x86) (only in 64-bit version)
 %PROMPT% Code for current command prompt format. Code is usually $P$G Code for current command prompt format. Code is usually $P$G
 %PSModulePath%  %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
 %PUBLIC%  %SystemDrive%\Users\Public
{Drive}:\$Recycle.Bin C:\Recycle.Bin C:\$Recycle.Bin
 %SystemDrive% C: C:
 %SystemRoot% The Windows directory, usually C:\Windows, formerly C:\WINNT  %SystemDrive%\Windows
 %TEMP% and %TMP%  %SystemDrive%\Documents and Settings\{username}\Local Settings\Temp  %SystemDrive%\Users\{username}\AppData\Local\Temp
 %USERDOMAIN% {userdomain} {userdomain}
 %USERDATA%  %SystemDrive%\Documents and Settings\{username}  %SystemDrive%\Users\{username}
 %USERNAME% {username} {username}
 %USERPROFILE%  %SystemDrive%\Documents and Settings\{username}  %SystemDrive%\Users\{username}
 %WINDIR% C:\Windows C:\Windows

In this list, there is no environment variable that refers to the location of the user's My Documents folder, so there is no standard method for setting a program's home directory to be the My Documents folder.

See also [link]

External links [link]

Unix [link]

Windows [link]


https://wn.com/Environment_variable

24 (season 1)

The first season of the American drama television series 24, also known as Day 1, was first broadcast from November 6, 2001, to May 21, 2002 on Fox. The season's storyline starts and ends at 12:00 a.m. on the day of the California presidential primary.

Season overview

The first season takes place on the day of a fictional U.S. presidential primary.

The season's main plot revolves around an assassination attempt on U.S. Senator from Maryland, David Palmer, a candidate for the Democratic Party presidential nomination, on the day of the primary in California. The central character is Jack Bauer, a former Delta Force operator who is the Director of the fictional Counter Terrorist Unit (CTU) in Los Angeles. Bauer becomes professionally as well as personally involved when his wife Teri and daughter Kim are kidnapped by the people behind the assassination plot.

The season is essentially divided into two halves:

  • The first half revolves around a mercenary group's efforts to control Jack Bauer by kidnapping his wife and daughter and forcing him to kill Senator Palmer. This culminates in Jack's successful rescue of his family.
  • 24 (season 6)

    The sixth season of the American drama television series 24, also known as Day 6, premiered in the United States on Fox on January 14, 2007, and concluded on May 21, 2007. The season's storyline begins and ends at 6:00 a.m. It is set 20 months after the events of the fifth season.

    Season overview

    The sixth season is set 20 months after season five. Over the last 11 weeks before Day 6, the United States has been targeted coast-to-coast in a series of suicide bombings. A man named Abu Fayed agrees to give the U.S. the location of Hamri Al-Assad, the supposed terrorist mastermind of these attacks, in exchange for former CTU Agent Jack Bauer with whom he has a personal grudge. As a result, President Wayne Palmer has negotiated the release of Bauer, who was illegally captured by Chinese government agents, under "high-price" terms.

    Season 6 can be divided into two main acts:

  • Jack is released from the Chinese prison, and works with CTU to take down suitcase nuke-armed terrorists, and discovers links to his own family in the process.
  • 12-hour clock

    The 12-hour clock is a time convention in which the 24 hours of the day are divided into two periods:a.m. (from the Latin ante meridiem, meaning "before midday") and p.m. (post meridiem, "after midday"). Each period consists of 12 hours numbered: 12 (acting as zero),1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11. The 24 hour/day cycle starts at 12 midnight (often indicated as 12 a.m.), runs through 12 noon (often indicated as 12 p.m.), and continues to the midnight at the end of the day.

    The 12-hour clock was developed over time from the mid-second millennium BC to the 16th century AD.

    History and use

    The natural day/night division of a calendar day forms the fundamental basis as to why each day is split into two cycles. Originally these were one cycle which could be tracked by the position of the Sun (day) followed by one cycle which could be tracked by the Moon and stars (night). This would eventually evolve into the two 12-hour periods that started at midnight (a.m.) and noon (p.m.) which are used today. Noon itself is rarely abbreviated today, but if it is, it is denoted M.

    12-hour clock

    The 12-hour clock is a time convention in which the 24 hours of the day are divided into two periods:a.m. (from the Latin ante meridiem, meaning "before midday") and p.m. (post meridiem, "after midday"). Each period consists of 12 hours numbered: 12 (acting as zero),1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11. The 24 hour/day cycle starts at 12 midnight (often indicated as 12 a.m.), runs through 12 noon (often indicated as 12 p.m.), and continues to the midnight at the end of the day.

    The 12-hour clock was developed over time from the mid-second millennium BC to the 16th century AD.

    History and use

    The natural day/night division of a calendar day forms the fundamental basis as to why each day is split into two cycles. Originally these were one cycle which could be tracked by the position of the Sun (day) followed by one cycle which could be tracked by the Moon and stars (night). This would eventually evolve into the two 12-hour periods that started at midnight (a.m.) and noon (p.m.) which are used today. Noon itself is rarely abbreviated today, but if it is, it is denoted M.

    AM PM (Endorphin album)

    AM:PM is the third album by the Australian band Endorphin, released in 2002. It was a two disc album, with the first labeled "AM", and the second labeled "PM". Eric Chapus (Endorphin's only band member) has stated that "AM reflects my life in the studio and PM reflects what I do live."

    Track listing

    AM

  • "Danger Zone" - 3:15
  • "Sex & Violence" - 3:09
  • "Tease" - 4:01
  • "The Best is Yet to Come" - 4:17
  • "Traffic" - 4:17
  • "Horizon" - 4:21
  • "Can't Hold On" - 3:26
  • "Antipodes" - 3:38
  • "Watching Shadows" - 3:17
  • "My Tomorrow" - 3:57
  • "Lesson 1" - 3:06
  • "Spell" - 5:39
  • PM

  • "Computer Games" - 3:53
  • "Viva" - 5:44
  • "Satie 3" - 6:04
  • "Pressure" - 4:00
  • "Get The Funk" - 4:19
  • "Fear" - 5:26
  • "Dare" - 4:47
  • "Flight 601" - 3:55
  • "Sex and Violence (Nash T vs. Archie Remix)" - 10:08
  • External links

  • Endorphinmusic.com Official website

  • Podcasts:

    PLAYLIST TIME:
    ×