Chapter Contents |
Previous |
Next |
Environment Variables |
The ISO/ANSI C standard requires
that a C library include the
getenv
function, which retrieves the value of
a named environment variable. Both the name and value are character strings.
The ISO/ANSI C standard does not describe the meaning of environment variables,
how they might be set, or even whether it is possible to define them. However,
the
getenv
function should be similar to
the
getenv
function under the UNIX environment,
and if the host operating system has a facility similar to UNIX environment
variables,
getenv
should provide a means
of accessing that facility.
These properties are fundamental to the behavior of UNIX environment variables:
export HOME=/u/george
system
function), the calling program's
environment variables are passed to the called program. The communication
is one way; that is, the caller passes the environment to the called program,
but any changes the called program makes to its environment are not available
to the caller.
exec
function enable a program to pass control to another program with
a specially built environment.
Secondary properties of UNIX environment variables include
environ
, which addresses the list of environment variables. Many older
programs access
environ
for environmental
information rather than calling
getenv
.
environ
. Some versions of the
UNIX environment implement functions like
putenv
to modify the environment, but these functions are not portable.
CMS Global Variables |
SAS/C Environment Variables |
SAS/C defines three scopes of environment variables: program, external, and permanent.
exec
functions is used.
Program-scope environment variables are set in one of
two ways. First, they may be specified on the program's command line as described
in Chapter 8, "Run-Time Argument Processing," in the
SAS/C Compiler and Library User's Guide. Or, for programs
invoked by the USS
exec
system call, they
may be passed by the caller of
exec
.
There are no limits on the size of program scope variable
names or values. The names are case insensitive; that is,
home
,
Home
, and
HOME
are considered to identify the same variable. (See USS Considerations for an
exception.)
When a program calls the
getenv
function to retrieve the value of an environment variable, the
scopes are searched in order. That is, first the program-scope variables
are checked, then the external-scope variables, and then the permanent-scope
variables. This enables you or the program to override the usual value with
a more temporary value for the duration of a program or session.
When a program calls the
putenv
or
setenv
function to modify
or add an environment variable, the change is made at program scope unless
some other scope is explicitly specified. Thus, a portable program that changes
its own environment will not affect any other program. Scopes are indicated
to
putenv
by a prefix on the environment
variable name followed by a colon, for example,
external:TZ
. Because colons are not commonly used in UNIX environment
variable names, this extension has little effect on portability.
Another extension in the SAS/C
environment variable implementation
supports group names for external- and permanent-scope variables. If an external-
or permanent-scope environment variable name contains a period, the portion
of the name before the period is considered to be the group name. For example,
the variable name
LC370.MACLIBS
defines
the variable
MACLIBS
in the group
LC370
. An environment variable without a group
name is considered to have a default group name of
CENV
.
CMS group names are limited to eight characters. For
this reason, in certain cases, environment variable names containing periods
may behave differently in different scopes. For example, the two environment
variables
TOOLONGFORME.NAME
and
TOOLONGFORANYONE.NAME
refer to the same variable for an external scope
but different variables for a program scope. This should not be a problem
in normal usage.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.