Enviroment Variables
From HPC
Contents |
Enviroment Variables
Enviroment variables are used by the operationing system, programs and possibly your scripts. This variables can be set and access from the command line as well as in scripts/programs.
You can set enviroment variables
export ENV_NAME=env_value
export ENV_NAME="env_value"
Example
export MY_DATA=/users/username/datafiles
Viewing the contents of enviroment variables
echo $ENV_NAME
Example
> echo $MY_DATA /users/username/datafiles >
Combining environment variables and strings in scripts
By using curl braces, you can concatenate environment variables and strings. For example $MY_DATA becomes ${MY_DATA}
#!/bin/bash myprogram ${MY_DATA}/datafile1.dat
This would run the following command
mprogram /users/username/datafiles/datafile1.dat
Passing variables from the command line to your script
You can pass variables from the command line to your script. Each option you specify after the script is accessible via an environment variables.
They are as follows
$0 (This is the name of the script) $1 (1st option) $2 (2nd option) and so on i.e. $3,$4,$5....
So the following
myscript datafile1.dat 20
The variables are populated as
$0 = myscript $1 = datafile1.dat $2 = 20
For example you might write your script so that you can specify which data file to use.
myscript datafile1.dat
The script looks like this
#!/bin/bash myprogram $1
Which would produce
myprgram datafile1.dat
General
PATH
This is the path the OS will search to find programs
export PATH=/dir/to/my/prog:$PATH
JAVA_HOME
The path to java
CFLAGS
C compiler flags
CXXFLAGS
C++ compiler Flags
SGE Variables
General
While job is running
SGE_O_SHELL The content of the SHELL environment variable in the context of job submission command.
SGE_O_TZ The content of the TZ environment variable in the context of the job submission command.
SGE_O_WORKDIR The working directory of the job submission command.
SGE_CKPT_ENV The checkpointing environment under which a checkpointing job runs. The checkpointing environment is selected with the qsub -ckpt command.
SGE_CKPT_DIR The path ckpt_dir of the checkpoint interface. Set only for checkpointing jobs. For more information, see the checkpoint(5) man page.
SGE_STDERR_PATH The path name of the file to which the standard error stream of the job is diverted. This file is commonly used for enhancing the output with error messages from prolog, epilog, parallel environment start and stop scripts, or checkpointing scripts.
SGE_STDOUT_PATH The path name of the file to which the standard output stream of the job is diverted. This file is commonly used for enhancing the output with messages from prolog, epilog, parallel environment start and stop scripts, or checkpointing scripts.
SGE_TASK_ID The task identifier in the array job represented by this task.
ENVIRONMENT Always set to BATCH. This variable indicates that the script is run in batch mode.
HOME The user's home directory path from the passwd file.
HOSTNAME The host name of the node on which the job is running.
JOB_ID A unique identifier assigned by the sge_qmaster when the job was submitted. The job ID is a decimal integer from 1 through 9,999,999.
JOB_NAME The job name, which is built from the qsub script filename, a period, and the digits of the job ID. You can override this default with qsub -N.
LOGNAME The user's login name from the passwd file.
NHOSTS The number of hosts in use by a parallel job.
NQUEUES The number of queues that are allocated for the job. This number is always 1 for serial jobs.
NSLOTS The number of queue slots in use by a parallel job.
PATH A default shell search path of:
/usr/local/bin:/usr/ucb:/bin:/usr/bin.
PE The parallel environment under which the job runs. This variable is for parallel jobs only.