Question & Answer
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
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 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 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.
[{"Product":{"code":"SSGU8G","label":"Informix Servers"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Not Applicable","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"10.0;11.5;9.4;11.7","Edition":"","Line of Business":{"code":"","label":""}},{"Product":{"code":"SSVT2J","label":"Informix Tools"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Not Applicable","Platform":[{"code":"","label":"UNIX"},{"code":"PF033","label":"Windows"}],"Version":"","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}},{"Product":{"code":"SSGKNY","label":"Informix C-ISAM"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Not Applicable","Platform":[{"code":"","label":"UNIX"},{"code":"PF033","label":"Windows"}],"Version":"Version Independent","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}},{"Product":{"code":"SSGU5D","label":"Informix Extended Parallel Server"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Not Applicable","Platform":[{"code":"","label":"UNIX"},{"code":"PF033","label":"Windows"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}},{"Product":{"code":"SSGHZP","label":"Informix OnLine"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Not Applicable","Platform":[{"code":"","label":"UNIX"},{"code":"PF033","label":"Windows"}],"Version":"Version Independent","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]
Was this topic helpful?
Document Information
Modified date:
19 August 2022
UID
swg21105412