Setting and unsetting environment variables

Technote (FAQ)


Question

How do you set and unset environment variables on Unix and Windows?

Answer

How you set environment variables depends on your operating system. On UNIX it also depends on what shell you are using.


UNIX

How you set environment variables in UNIX depends on which shell you are using.

Most shells fall into one of two groups. The C shell-like shells and the Bourne-like shells. Each set uses different commands to set environment variables. Here is a list of popular shells and which syntax they use:

    Shells using C shell syntax
    Shells using Bourne shell syntax
    C shell, tcsh
    sh, rsh, ksh, bash, and zsh

C shell

In C shell you set environment variables with the setenv command. The syntax for setenv is as follows:
    setenv name  [ value ]

The square brackets ([]) indicate that value is optional.

If there is already an environment variable named name then value will be assigned to that variable. If there is not an environment variable named name then one will be created.

    Example:

    This command sets the environment variable INFORMIXDIR to a value of /usr/var/informix:
      setenv INFORMIXDIR /usr/var/informix


If value is omitted then name will be set to a null value but it will still be set. To unset an environment variable you must use the unsetenv command. The format for unsetenv is as follows:
    unsetenv name



Bourne shell

To set an environment variable in the Bourne shell use a command line with the following syntax:
    name =[ value ];export name

The square brackets ([]) indicate that value is optional.

This is actually two commands separated by a semicolon. The first ( name = value) assigns value to the environment variable named name. If name does not yet exist it will be created.

The second command ( export name) makes sure that the environment variable name will be passed on to any programs that you start from this shell. A common mistake is to forget the export command. This mistake prevents the executed program from seeing the environment variable at all.

    Example:

    This command line will set the environment variable INFORMIXDIR to a value of /usr/var/informix:
      INFORMIXDIR=/usr/var/informix;export INFORMIXDIR
If value contains any special characters like spaces or semicolons it must be enclosed in either single or double quotes. If it is omitted then name will still be set but will have a null value.


    Example:

    This command sets the DELIMIDENT environment variable to a null value.
      DELIMIDENT=;export DELIMIDENT

To unset an environment variable you must use the unset command. The format for the unset command is as follows:
    unset name


WINDOWS

Windows NT

To set an environment variable on Windows NT do the following:
    1. Choose Start->Settings->Control Panel and start the System application.

    2. Click on the Environment tab.


    3. To modify an existing environment variable click on the variable in the System Variables list then modify the value in the Value text box and click the Set button.

    If the environment variable you want to set does not already exist then click on any entry in the System Variables list then change the Variable text box to the name of the variable and the Value text box to the value then click the Set button.

    4. Click OK

The changes will take effect immediately but most programs only check the values of environment variables when they first start running. This means that you do not have to restart Windows but you may need to restart your application for the changes to take effect.

The above procedure modifies system environment variables. That means that if you set an environment variable this way then anyone that uses the computer will have that environment variable set.


Windows 2000/XP

To set, modify, or unset an environment variable on Windows 2000 or Windows XP do the following:

    1. Choose Start->Settings->Control Panel->System to start the System application.

    2. Click on the Advanced tab and click the Environment Variables button. This opens the Environment Variables window.
    3. To create a new environment variable click on New... to open the New System Variable dialog. Enter the environment variable's name in the Variable Name field and the value in the Variable Value field then click OK.

    To change the value of an existing environment variable click the variable in the System variables list then click on the Edit... button to bring up the Edit System Variable dialog. Modify the value in the Variable Value field then click OK.

    To unset an environment variable click on the variable in the System variables list then click Delete.

    4. Click on OK.
The changes will take effect immediately but most programs only check the values of environment variables when they first start running. This means that you do not have to restart Windows but you may need to restart your application for the changes to take effect.

The above procedure modifies system environment variables. That means that if you set an environment variable this way then anyone that uses the computer will have that environment variable set.


Windows 95/98/ME

On Windows 95, Windows 98, and Windows ME you must add set statements to the file c:\autoexec.bat

The syntax of the set command is as follows:
    set name= value
      name
        The environment variable name.

      value
        The value to which to set the environment variable.

If there is already an environment variable named name then that environment variable is set to value. If an environment variable named name does not yet exist it will be created.

After adding the set command(s) to the file c:\autoexec.bat you must shutdown and restart Windows before the environment variable settings will be used.

On Windows the names of environment variables are case insensitive so, for example, the environment variable Informixdir is the same as the environment variable INFORMIXDIR.


Cross reference information
Segment Product Component Platform Version Edition
Information Management Informix Tools Not Applicable UNIX, Windows
Information Management Informix C-ISAM Not Applicable UNIX, Windows Version Independent
Information Management Informix Extended Parallel Server (XPS) Not Applicable UNIX, Windows All Versions
Information Management Informix OnLine Not Applicable UNIX, Windows Version Independent
Information Management Informix SE Not Applicable UNIX, Windows Version Independent

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

Informix Servers

Software version:

9.4, 10.0, 11.5, 11.7

Operating system(s):

AIX, HP-UX, Linux, Solaris, Windows

Reference #:

1105412

Modified date:

2004-02-23

Translate my page

Machine Translation

Content navigation