Getting and Setting Environment Variables

Exporting just Variables

Assignments prefixed with the export keyword will be exported to recipes as environment variables:

export RUST_BACKTRACE := "1"

test:
  # will print a stack trace if it crashes
  cargo test

Parameters prefixed with a $ will be exported as environment variables:

test $RUST_BACKTRACE="1":
  # will print a stack trace if it crashes
  cargo test

Exported variables and parameters are not exported to backticks in the same scope.

export WORLD := "world"
# This backtick will fail with "WORLD: unbound variable"
BAR := `echo hello $WORLD`
# Running `just a foo` will fail with "A: unbound variable"
a $A $B=`echo $A`:
  echo $A $B

When export is set, all just variables are exported as environment variables.

Unexporting Environment Variables1.29.0

Environment variables can be unexported with the unexport keyword:

unexport FOO

@foo:
  echo $FOO
$ export FOO=bar
$ just foo
sh: FOO: unbound variable

Getting Environment Variables from the environment

Environment variables from the environment are passed automatically to the recipes.

print_home_folder:
  echo "HOME is: '${HOME}'"
$ just
HOME is '/home/myuser'

Setting just Variables from Environment Variables

Environment variables can be propagated to just variables using the functions env_var() and env_var_or_default(). See environment-variables.