Skip to main content

export Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for exporting shell variables and functions to child processes with export in Bash

The `export` builtin marks shell variables and functions so child processes can inherit them. This cheatsheet covers variable export, function export, removing the export property, and common shell-session patterns.

Basic Syntax

Core export command forms in Bash.

CommandDescription
export VAR=valueCreate and export a variable
export VARExport an existing shell variable
export -pList all exported variables
export -n VARRemove the export property
help exportShow Bash help for export

Export Variables

Use export to pass variables to child processes.

CommandDescription
export APP_ENV=productionExport one variable
PORT=8080; export PORTDefine first, export later
export PATH="$HOME/bin:$PATH"Extend PATH
export EDITOR=nanoSet a default editor
export LANG=en_US.UTF-8Set a locale variable

Export for One Shell Session

These changes last only in the current shell session unless you save them in a startup file.

CommandDescription
export DEBUG=1Enable a debug variable for the current session
export API_URL=https://api.example.comSet an application endpoint
export PATH="$HOME/.local/bin:$PATH"Add a per-user bin directory
echo "$DEBUG"Verify that the exported variable is set
bash -c 'echo "$DEBUG"'Confirm the child shell inherits the variable

Export Functions

Bash can export functions to child Bash shells.

CommandDescription
greet() { echo "Hello"; }Define a shell function
export -f greetExport a function
bash -c 'greet'Run the exported function in a child shell
export -nf greetRemove the export property from a function

Remove or Reset Exports

Use these commands when you no longer want a variable inherited.

CommandDescription
export -n VARKeep the variable, but stop exporting it
unset VARRemove the variable completely
unset -f greetRemove a shell function
export -n PATHStop exporting PATH in the current shell
`envgrep ‘^VAR='`

Make Variables Persistent

Add export lines to shell startup files when you want them loaded automatically.

FileUse
~/.bashrcInteractive non-login Bash shells
~/.bash_profileLogin Bash shells
/etc/environmentSystem-wide environment variables
/etc/profileSystem-wide shell startup logic
source ~/.bashrcReload the current shell after editing

Troubleshooting

Quick checks for common export problems.

IssueCheck
A child process cannot see the variableConfirm you used export VAR or export VAR=value
The variable disappears in a new terminalAdd the export line to ~/.bashrc or another startup file
A function is missing in a child shellExport it with export -f name and use Bash as the child shell
The shell still sees the variable after export -nexport -n removes inheritance only; use unset to remove the variable completely
The variable is set but a command ignores itCheck whether the program reads that variable or expects a config file instead

Use these guides for broader shell and environment-variable workflows.

GuideDescription
export Command in LinuxFull guide to export options and examples
How to Set and List Environment Variables in LinuxBroader environment-variable overview
env cheatsheetInspect and override environment variables
Bash cheatsheetQuick reference for Bash syntax and shell behavior