Setting environment variables

You use environment variables to set values that programs need. Specify the value of an environment variable by using the export command or the putenv() POSIX function. If you do not set an environment variable, either a default value is applied or the variable is not defined.

An environment variable defines some aspect of a user environment or a program environment that can vary. For example, you use the COBPATH environment variable to define the locations where the COBOL run time can find a program when another program dynamically calls it. Environment variables are used by both the compiler and runtime libraries.

When you installed IBM COBOL for AIX, the installation process set environment variables to access the COBOL for AIX compiler and runtime libraries. To compile and run a simple COBOL program, the only environment variables that need to be set are NLSPATH and LANG. These variables are usually set at installation.

You can change the value of an environment variable in either of two places by using the export command:

You can also set environment variables from within a COBOL program by using the putenv() POSIX function, and access the environment variables by using the getenv() POSIX function.

Some environment variables (such as COBPATH and NLSPATH) define directories in which to search for files. If multiple directory paths are listed, they are delimited by colons. Paths that are defined by environment variables are evaluated in order, from the first path to the last in the export command. If multiple files that have the same name are defined in the paths of an environment variable, the first located copy of the file is used.

For example, the following export command sets the COBPATH environment variable (which defines the locations where the COBOL run time can find dynamically accessed programs) to include two directories, the first of which is searched first:

export COBPATH=/users/me/bin:/mytools/bin

Example: setting and accessing environment variables

related tasks  
Tailoring your compilation