Environment variables

De Wiki de Calcul Québec
Aller à : Navigation, rechercher
Cette page est une traduction de la page Variables d'environnement et la traduction est complétée à 100 % et à jour.

Autres langues :anglais 100% • ‎français 100%

Sommaire

Introduction

Linux uses a list of environment variables to define a user's workspace. While environment variables can contain any type of configuration options, they are most commonly used to store list of paths.

To display the value of a variable, one can use the echo command. For example, for the PATH variable:

[name@server $] echo $PATH


The following commands show how to modify the value of an environment variable and add a path to a path variable. With [Bash], the commands are

 
 [name@server $] export TMPDIR=$HOME/tmp
 [name@server $] export PATH=$PATH:$HOME/bin
 


In tcsh:

 
 [name@server $] setenv TMPDIR $HOME/tmp
 [name@server $] setenv PATH $PATH:$HOME/bin
 


You may have noticed that using the dollar sign ($) before the name of a variable fetches the value of that variable. It is also possible to add content to a variable like we did for the PATH. This is very useful for path variables.

To get the list of environment variables that are defined in your environment, you can use the command

[name@server $] printenv


Path variables

Path variables contain a list of directories separated with colons ":". Those paths are the ones that are browsed by the system to find libraries and tools. You will likely want to prepend or append to those variables when you will create your own modules. Here are the main variables.

Variables to run a program

A typical catch about those variables is that they are local to a given session. This means that if you change their values in your interactive shell, and then submit a job script, the changes you did in your interactive session will not necessarily be ported to the compute node. You need to make sure to set them within your submit script.

PATH
List of directories in which the system looks for binaries.
Example within a module: prepend-path PATH $root/bin
LD_LIBRARY_PATH
List of directories in which the system looks for dynamically linked libraries.
Ex: prepend-path LD_LIBRARY_PATH $root/lib

Variables for compiling

CPATH
List of directories in which the precompiler looks for header files (works with Gnu and Intel). Those are browsed if the precompiler does not find the header files in the directories given at command line (-I) option
Ex: prepend-path CPATH $root/include
FPATH
Same as CPATH, but for Fortran codes and .mod files
C_INCLUDE_PATH
Same as CPATH. However, those directories will be browsed only if the header file is not within those listed on the command line, nor within the CPATH, nor within the system default directories
CPLUS_INCLUDE_PATH
Similar to C_INCLUDE_PATH, but for C++ compiler. Note that C++ compilers do not use the C_INCLUDE_PATH, even for C header files. It is therefore important to define CPLUS_INCLUDE_PATH if a C header file can be used directly from C++.
LIBRARY_PATH
List of directories in which the linker (ld) looks for libraries when linking a program (both for .so and .a files). Those directories are used only if the library is not found within the directories listed on the command line with the -L option.

Other variables

PYTHONPATH
List of directories used by Python to search for a package (import command).
Ex: prepend-path PYTHONPATH $root/lib/python2.7/site-packages
PERL5LIB
List of directories used for Perl 5 to search for a package
Ex: prepend-path PERL5LIB $root/lib64/perl5
MANPATH
List of directories used for the man pages
Ex: append-path MANPATH $root/share/man
PKG_CONFIG_PATH
List of directories used by pkg-config to find libraries
Ex: prepend-path PKG_CONFIG_PATH $root/lib/pkgconfig

Single valued variables

HOME
Default folder in which you land when you login to a server. This folder contains many configuration files. You should never change this variable.
TMPDIR
Folder in which to write temporary folders. This variable is used by some tools, and is the best place to put temporary files.
Ex: export TMPDIR=$HOME/tmp
SHELL
Name of the shell to be used. This variable must contain the full path of the shell.
Ex: export SHELL=/bin/tcsh
DISPLAY
This variable is used in interactive mode for vizualisation.
Ex: export DISPLAY=localhost:10.0

Moab environment variables

The list of environment variables defined by Moab is available here.

Torque/PBS environment variables

The list of environment variables defined by Torque is available here.

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Ressources de Calcul Québec
Outils
Partager