Teamprise Knowledge Base

TKB00015 Defining an Environment Variable

Last updated 2008-12-12 15:00:37 UTC by Shaw Terwilliger

Overview

An environment variable is a mapping of a name to a value which is visible to processes on Unix (including Mac OS X) and Windows operating systems. Environment variables exist so that a program's behavior can be altered by setting their values. A program may check for zero, one, or many environment variable values when it runs. The names of the environment variables a program will look for are generally hard-coded into the program; the values are defined by the user. Some programs may simply check for the existence of an environment variable (whether it has been "set") and ignore its contents (which may be empty or set to some text, numeric, or other value).

Configuration

An environment variable may be set temporarily for a single shell (or command prompt) or persistently (so that it affects all future shells or command prompts). There are not actually two kinds of environment variables, just two ways of setting them. This article details the steps for setting persistent environment variables. On Unix, these variables and their values are stored in shell initialization scripts in the user's home directory. On Windows, these variables and their values are stored in the registry (but are modified through the Windows Explorer shell).

Setting Variables on Windows

To set the environment variable for your Windows user:

  1. Click the Start button
  2. Right-click on My Computer and choose Properties
  3. Click the Advanced tab, then click the Environment Variables button
  4. Click the New button in the top half of the window
  5. In the Variable name text box, type the desired name
  6. In the Variable value text box, type the desired value
  7. Click OK in all the open windows to apply your changes

All new command prompt windows will start programs with the newly configured environment variable. If you decide you do not want a program's behavior to be affected by an environment variable, repeat the steps above to get to the Environment Variables window but click Delete instead of New. All future command prompt windows will be affected.

Setting Variables on Unix

sh

Open the file ~/.profile in a text editor. At the end of a file, create two lines containing text like the following (substituting the desired name and value):

NAME="value"
export NAME

Save and close the file.

All new sh shells for your Unix user will now have the environment variable name set to value value. If you decide you do not want a program's behavior to be affected by the environment variable, simply remove the two lines from ~/.profile. After logging out and logging back in, programs run from your sh shell will no longer have the name environment variable set.

bash/zsh/ksh

Open the file ~/.bashrc (bash), ~/.zshrc (zsh), or ~/.profile (ksh) in a text editor. At the end of a file, create a line containing text like the following (substituting the desired name and value):

export NAME="value"

Save and close the file.

All new shells for your Unix user will now have the environment variable name set to value value. If you decide you do not want a program's behavior to be affected by the environment variable, simply remove the line from the initialization file you edited. After logging out and logging back in, programs run from your shell will no longer have the name environment variable set.

csh/tcsh

Open the file ~/.cshrc (~/.tcshrc for tcsh) in a text editor. At the end of a file, create a line containing text like the following (substituting the desired name and value):

setenv NAME "value"

Save and close the file.

All new csh/tcsh shells for your Unix user will now have the environment variable name set to value value. If you decide you do not want a program's behavior to be affected by the environment variable, simply remove the line from the initialization file you edited. After logging out and logging back in, programs run from your csh/tcsh shell will no longer have the name environment variable set.

Products affected:

  • Teamprise Command Line Client
  • Teamprise Explorer
  • Teamprise Plugin for Eclipse

Releases affected:

  • All

Platforms affected:

  • All

This article is referenced by these articles:

Keywords: environment variable env