The `ENVIRONMENT`_ options allow control of the environment exported to jobs via a set of RULE expressions. The currently supported rules are
If a rule begins with
-, then the rest of the rule is a pattern which removes matching environment variables. If the pattern starts with/, it is a regex(7), optionally ending with/, otherwise the pattern is considered a shell glob(7) expression.
- Examples:
-*or-/.*/filter all environment variables creating an empty environment.If a rule begins with
^then the rest of the rule is a filename from which to read more rules, one per line. The~character is expanded to the user's home directory.
- Examples:
~/envfilereads rules from file$HOME/envfileIf a rule is of the form
VAR=VAL, the variableVARis set toVAL. Before being set, however,VALwill undergo simple variable substitution using the Pythonstring.Templateclass. This simple substitution supports the following syntax:
$$is an escape; it is replaced with$
$varwill substitutevarfrom the current environment, falling back to the process environment. An error will be thrown if environment variablevaris not set.
${var}is equivalent to$varAdvanced parameter substitution is not allowed, e.g.
${var:-foo}will raise an error.
VALmay also contain a mustache template, in which case the template will be substituted in the job shell with the corresponding value before launching job tasks. See `MUSTACHE TEMPLATES`_ for more information.
- Examples:
PATH=/bin,PATH=$PATH:/bin,FOO=${BAR}something,PATH=${PATH}:/{{tmpdir}}/binOtherwise, the rule is considered a pattern from which to match variables from the process environment if they do not exist in the generated environment. E.g.
PATHwill exportPATHfrom the current environment (if it has not already been set in the generated environment), andOMP*would copy all environment variables that start withOMPand are not already set in the generated environment. It is important to note that if the pattern does not match any variables, then the rule is a no-op, i.e. an error is not generated.
- Examples:
PATH,FLUX_*_PATH,/^OMP.*/
Since we always starts with a copy of the current environment,
the default implicit rule is * (or --env=*). To start with an
empty environment instead, the -* rule or --env-remove=* option
should be used. For example, the following will only export the current
PATH to a job:
flux run --env-remove=* --env=PATH ...
Since variables can be expanded from the currently built environment, and
--env options are applied in the order they are used, variables can
be composed on the command line by multiple invocations of --env,
e.g.:
flux run --env-remove=* \
--env=PATH=/bin --env='PATH=$PATH:/usr/bin' ...
Note that care must be taken to quote arguments so that $PATH is not
expanded by the shell.
This works particularly well when specifying rules in a file:
-*
OMP*
FOO=bar
BAR=${FOO}/baz
The above file would first clear the environment, then copy all variables
starting with OMP from the current environment, set FOO=bar,
and then set BAR=bar/baz.