You can add it to the file .profile
or your login shell profile file (located in your home directory).
To change the environmental variable "permanently" you'll need to consider at least these situations:
- Login/Non-login shell
- Interactive/Non-interactive shell
bash
- Bash as login shell will load
/etc/profile
, ~/.bash_profile
, ~/.bash_login
, ~/.profile
in the order
- Bash as non-login interactive shell will load
~/.bashrc
- Bash as non-login non-interactive shell will load the configuration specified in environment variable
$BASH_ENV
$EDITOR ~/.profile
#add lines at the bottom of the file:
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
export ORACLE_HOME=/usr/lib/oracle/11.2/client64
zsh
$EDITOR ~/.zprofile
#add lines at the bottom of the file:
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
export ORACLE_HOME=/usr/lib/oracle/11.2/client64
ksh
$EDITOR ~/.profile
#add lines at the bottom of the file:
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
export ORACLE_HOME=/usr/lib/oracle/11.2/client64
bourne
$EDITOR ~/.profile
#add lines at the bottom of the file:
LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
ORACLE_HOME=/usr/lib/oracle/11.2/client64
export LD_LIBRARY_PATH ORACLE_HOME
csh or tcsh
$EDITOR ~/.login
#add lines at the bottom of the file:
setenv LD_LIBRARY_PATH /usr/lib/oracle/11.2/client64/lib
setenv ORACLE_HOME /usr/lib/oracle/11.2/client64
If you want to make it permanent for all users, you can edit the corresponding files under /etc/
, i.e. /etc/profile
for Bourne-like shells, /etc/csh.login
for (t)csh, and /etc/zsh/zprofile
and /etc/zsh/zshrc
for zsh.
Another option is to use /etc/environment
, which on Linux systems is read by the PAM module pam_env
and supports only simple assignments, not shell-style expansions. (See Debian's guide on this.)
These files are likely to already contain some assignments, so follow the syntax you see already present in your file.
Make sure to restart the shell and relogin the user, to apply the changes.
If you need to add system wide environment variable, there's now /etc/profile.d
folder that contains sh script to initialize variable.
You could place your sh script with all you exported variables here.
Be carefull though this should not be use as a standard way of adding variable to env on Debian.
All the processing done by SLURM (by sbatch
, specifically) is done before bash is invoked, so bash won't help you here. The script could be in any language, it wouldn't matter: the #SBATCH
are only coincidentally bash comments, what matters is that they're sbatch
directives.
Options can be specified in the file so as to provide a convenient way to always use the same parameters for a particular script. If you want to use different options, pass them on the command line of sbatch
. You can write a wrapper script that runs sbatch
if you want to build up options from certain specific parameters. You can pass the job script as standard input (a here document is convenient) instead of keeping it in a separate file if you prefer.
#!/bin/sh
sbatch --time=5:00:00 --ntasks="$1" --mem-per-cpu=1024M <<'EOF'
#!/bin/sh
MyProgram.exe
EOF
Best Answer
Will that be enough for what you're wanting to do?
To get only the value for e.g. MaxArraySize:
As a shell function:
These are not environment variables in the Unix sense, but configuration settings in Slurm. They are variables for configuring the "Slurm environment" though.