A variable consists of a name and its assigned value. Shell variables are variables that are used within a given shell; environment variables are variables that have been exported to the environment. Both types of variables take string values. Operating systems, applications, and users can read and set values of variables to control the behavior of the system.
Windows has two types of environment variables: user variables and system variables. User variables are set for each user who logs on. By default, each user usually has a TMP and a TEMP user variable that are both set to temporary directories. System variables are set for all users who log on to the system. The variable WINDIR, which is set to Windows installation directory, is an example of a system variable.
To view and set environment variables in Windows XP, click Start, right-click My Computer and click Properties. Next, click the Advanced tab, and then click Environment Variables. To view and set environment variables in Windows 2000, on the desktop, right-click My Computer and click Properties. Next, click the Advanced tab, and then click Environment Variables. To view and set environment variables in Windows NT 4.0, right-click My Computer, click Properties, and then click the Environment tab.
Within a shell, some variables establish characteristics of the shell environment, and some variables reflect how your environment is changing as you interact with the shell. There are other variables you can create to use with shell scripts.
The shell also inherits variables from Windows. For example, when you install Windows Services for UNIX, new system variables are created, including INTERIX_ROOT and SFUDIR. These system variables are inherited when you open the Korn shell or the C shell.
The following table lists and describes some common environment variables. Some are inherited from Windows; others are set when you open an Interix shell.
Variable | Description |
---|---|
COMPUTERNAME | The name of your computer, which is set in Windows. |
HOME | Your home directory. To learn more about creating a home directory in Windows, see Create a home directory. The value of HOME can also be set using shell startup files. To learn more about startup files, see Customizing your startup files. |
LOGNAME | The name with which you logged on to Windows. When using a shell through a Telnet session, the value of LOGNAME is the name with which you logged on to Telnet. |
INTERIX_ROOT | The directory in which you installed Windows Services for UNIX. The default is the SFU folder of your system drive. For example, /dev/fs/C/SFU. To learn more about Interix path names, see Path names in Interix. |
INTERIX_ROOT_WIN | The folder in which you installed Windows Services for UNIX, but in Windows format. For example, C:\SFU. |
PATH | A list of folders that are searched when you run a command. The command can be either a program or a script. In the Korn shell, the PATH is taken from the startup file called /etc/profile. In the C shell, the PATH comes from the startup file called /etc/csh.login. To learn more about Interix search paths, see Search paths. |
SFUDIR | The installation directory for Windows Services for UNIX. |
TERM | Your terminal type. Interix sets the value of TERM to interix, which is required by Interix utilities. To learn more about terminals, see Terminals and other devices. |
TMPDIR | A directory for temporary files. In the Korn shell, the TMPDIR is taken from the startup file called /etc/profile. In the C shell, the TMPDIR comes from the startup file called /etc/csh.login. The value of TMPDIR is set to /tmp by default. |
USERDOMAIN | The Windows domain in which you logged on. If you are logged on to the local computer, the value of USERDOMAIN is set to the local computer name. |
There are many other environment variables. Use the env(1) command to see a list of the environment variables of your current shell.
You can refer to the value of a variable by prefixing it with a dollar sign ($) or surrounding it with ${}. For example, both $HOME and ${HOME} refer to your home directory. You can display the value of an individual variable by using the echo(1) command. For example, echo $HOME returns the value of your home directory. The standard convention for referring to environment variables in the Korn shell is by using all uppercase letters, such as HOME or PATH.