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
Syntax
export NAME[=VALUE]... NAME=VALUE command
Parameters
| Parameter | Description |
|---|---|
-n |
Remove the export attribute. |
-p |
List exported variables. |
Examples
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.
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.
Related
source· Run a file's commands in the current shell, so its variables and functions stay defined; . is the POSIX spelling.declare· Declare variables with attributes: arrays, associative arrays, integers, read-only values and exported variables.- Bash Environment Variables and PATH · tutorial