logo

How to pass environment variables when submitting PBS jobs 📂Programing

How to pass environment variables when submitting PBS jobs

Overview

When submitting jobs to PBS, you can pass environment variables from the execution environment to the job script. There are two options:

  • -v: passes only the specific variables the user specifies.
  • -V: passes all variables from the current terminal environment.

Code1

-v {variable_name1}={value1},{variable_name2}={value2}

Using the -v option, you can pass environment variables as shown above. Separate multiple variables with commas and do not use whitespace (spaces). Upload the test file as a job as shown below. The two variables DATE and TITLE were passed.

(base) [user ~]$ qsub -v DATE=2026_05_01,TITLE=Freshrimpsushi test

The contents of the test file are as follows. It prints the two variables.

#!/bin/sh
#PBS -N test
#PBS -q full
#PBS -l select=1:ncpus=1:ngpus=0

echo $DATE $TITLE

exit 0

The execution result is as follows.

2026_05_01 Freshrimpsushi

The uppercase -V passes all environment variables from the current terminal. Remember that with great power comes great responsibility. Be careful, as this may cause the job to behave in unintended ways.