Bash 5 reference · Shell Builtins and Syntax

export (Bash builtin)

Mark variables so child processes inherit them; one-off variables can also be set for a single command.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

export NAME[=VALUE]...   NAME=VALUE command

Parameters

ParameterDescription
-n Remove the export attribute.
-p List exported variables.

Examples

Plain versus exported
token=abc
bash -c 'echo "child: [${token:-}]"'
export token
bash -c 'echo "child: [$token]"'

Output

child: []
child: [abc]

Run this on your computer — see “Get Started” for setup.

A variable for one command
LOG_LEVEL=debug bash -c 'echo "$LOG_LEVEL"'
echo "afterwards: [${LOG_LEVEL:-unset}]"

Output

debug
afterwards: [unset]

Run this on your computer — see “Get Started” for setup.

Was this page helpful?