variables

export

Marks a shell variable (or function with -f) for export to the environment of subsequently executed commands. Without arguments, prints all exported variables in a re-importable format.

export [-fnp] [NAME[=VALUE] ...]

Common flags / operators

Flag / Operator Purpose
-p Print exported names in reusable form
-n Remove export attribute (variable stays set)
-f Export a function instead of a variable
NAME=VALUE Assign and export in one step

Examples

export PATH="$HOME/bin:$PATH"

Prepend ~/bin to PATH for child processes.

export EDITOR=vim

Set EDITOR so tools like git and crontab pick it up.

export -f myfunc

Make myfunc available in subshells.

export -n TMP_VAR

Unexport TMP_VAR — it stays in the current shell only.

Gotcha

'FOO=bar cmd' sets FOO only for that one command — no export needed. Exported variables can leak secrets into subprocesses; use temporary env prefixes instead when possible.

Related

← All Bash builtins · Linux commands