env.gex - GrADS v1.9 Extensions for Environment Variable Manipulation

- NAME
- SYNOPSIS

- GrADS Commands:

- DESCRIPTION
- EXAMPLES

- Using getenv to print the value of a list of environment variables
- Using setenv to set the value of a given environment variable
- Using printenv expand environment variables in a string
- Get the process id (PID) for creating temporary files, etc
- Using env to expand environment variables, then execute a GrADS command
- Setting environment variables based on another env variable
- Saving complicated expressions in environment variables (like aliases)

- COMMANDS PROVIDED

- env CMD
- getenv NAMEs
- setenv NAME VALUE
- printenv STRING
- xenv STRING
- @ STRING

- SEE ALSO
- AUTHOR
- COPYRIGHT

# NAME

env.gex - GrADS v1.9 Extensions for Environment Variable Manipulation

# SYNOPSIS

### GrADS Commands:

  env CMD - Expands environment variables in CMD and executes it

  getenv NAME - Print value of NAME

  setenv NAME VALUE - Set environment variable NAME to VALUE

  printenv STRING - Expands all environment variables in <STRING>

# DESCRIPTION

This library implements GrADS extensions (gex) with commands for setting and retriving environment variables. In addition it can exapand all environment variables in a GrADS command string and then execute the command after the expansion takes places.

Environment variables can be used in GrADS in a variety of ways. Prior to starting GrADS you can set up environment variables with the locations of your data directories and use this environment variable when opening your files, for example. Another useful application is for holding truly global information which persists throughout the extent of your GrADS session. You can use this technique for communicating between GrADS scripts that are invoked from different `run` commands.

# EXAMPLES

### Using getenv to print the value of a list of environment variables

       ga-> getenv USER HOME TMPDIR
       Environment variable USER = dasilva
       Environment variable HOME = /Users/dasilva
       Environment variable TMPDIR = <undef>

Notice that environment variable `TMPDIR` was not defined in this case.

### Using setenv to set the value of a given environment variable

       ga-> setenv OPENGRADS /share/dasilva/opengrads
       Environment variable OPENGRADS = /share/dasilva/opengrads

### Using printenv expand environment variables in a string

       ga-> printenv $HOME/src/grads/test_data
       /Users/dasilva/src/grads/test_data

Notice that undefined variables exapand to a blank string:

       ga-> printenv Undefined variable FOO = <$FOO>
       Undefined variable FOO = <>

### Get the process id (PID) for creating temporary files, etc

       ga-> printenv /tmp/tempfile.$$
       /tmp/tempfile.21386

### Using env to expand environment variables, then execute a GrADS command

      ga-> env open $OPENGRADS/test_data/model.ctl

Notice that you can use @ as a short hand for env:

      ga-> @ open $OPENGRADS/test_data/model.ctl

### Setting environment variables based on another env variable

Using the @ short-hand for env:

       ga-> @ setenv FILE $HOME/data/model.ctl
       setenv FILE /Users/dasilva/data/model.ctl
       Environment variable FILE = /Users/dasilva/data/model.ctl

       ga-> @ open $FILE
       open /Users/dasilva/data/model.ctl
       Scanning description file:  /Users/dasilva/data/model.ctl
       Data file /Users/dasilva/data/model.grb is open as file 1
       LON set to 0 360
       LAT set to -90 90
       LEV set to 1000 1000
       Time values set: 1987:1:1:0 1987:1:1:0

### Saving complicated expressions in environment variables (like aliases)

You can use env variables to save long expressions:

       ga-> setenv EXPR ua;va;sqrt(ua*ua+va*va)
       Environment variable EXPR = ua;va;sqrt(ua*ua+va*va)

       ga-> @ display $EXPR
       display ua;va;sqrt(ua*ua+va*va)

# COMMANDS PROVIDED

The following commands are loosely based on the C-Shell syntax:

## env CMD

This command expands environment variables in string CMD and executes it as a GrADS command after expansion. Example:

       ga-> env open $HOME/data/model.ctl
       open /Users/dasilva/data/model.ctl
       Scanning description file:  /Users/dasilva/data/model.ctl
       Data file /Users/dasilva/data/model.grb is open as file 1
       LON set to 0 360
       LAT set to -90 90
       LEV set to 1000 1000
       Time values set: 1987:1:1:0 1987:1:1:0

## getenv NAMEs

This command takes a list of environment variables and prints the value of each one. Example:

       ga-> getenv USER HOME DISPLAY
       Environment variable USER = dasilva
       Environment variable HOME = /Users/dasilva
       Environment variable DISPLAY = :0.0

## setenv NAME VALUE

This command sets environment variable NAME to VALUE. Example:

       ga-> setenv DATADIR /archive/data
       Environment variable DATADIR = /archive/data

## printenv STRING

This command expands all environment variables in STRING, printing the result to the screeen. Example:

       ga-> printenv My home directory is $HOME
       My home directory is /Users/dasilva

## xenv STRING

Same as printenv.

## @ STRING

Same as env.

# SEE ALSO

- http://opengrads.org/ - OpenGrADS Home Page

- http://opengrads.org/wiki/index.php - OpenGrADS User Defined Extensions

- http://www.iges.org/grads/ - Official GrADS Home Page

# AUTHOR

Arlindo da Silva (dasilva@opengrads.org)

# COPYRIGHT

Copyright (C) 2007-2008 Arlindo da Silva; All Rights Reserved.

This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

env.gex - GrADS v1.9 Extensions for Environment Variable Manipulation