export
Set a variable with export, read it with $NAME, list them all with env — and why programs only see exported ones.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
export APP_ENV=production -
echo $APP_ENV -
env | grep APP -
printenv PATH -
unset APP_ENV -
export
How it works
An environment variable is a name with a value that programs can read: HOME, PATH, USER. export NAME=value creates one (no spaces around =).
Without export, NAME=value is only seen by your shell. With it, every script and program you start from here sees it too. It lasts until you close the terminal.
Syntax
export NAME=value | echo $NAME | unset NAME
Options
| Option | What it does |
|---|---|
NAME=value | create or change a variable (no spaces around =) |
$NAME | the value, wherever you write it |
env | list every exported variable |
unset NAME | remove it |
Good to know
export NAME = value(with spaces) fails: the shell reads it as three separate words.- To keep a variable for every new terminal, put the
exportline in~/.bashrc. Containers get theirs withdocker run -e NAME=value.