Shell and environment

Command export

Export environment variable

Linux · Bash examples · commands run on the selected server

When to use export

Use export to make a shell variable available to subsequently launched child processes. It does not update already running applications or automatically persist settings across new SSH sessions.

Syntax

export [NAME[=VALUE]…]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-p
Show exported variables Bash.
-n NAME
In Bash, remove the export flag without deleting the value.

Usage examples

Export a non-secret setting

export APP_ENV=staging

The variable is set and marked for inheritance in this shell.

Check variable in child process

sh -c 'printf "%s\n" "$APP_ENV"'

A child shell demonstrates that the exported value is available to it.

Add custom directory to PATH

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

A user command directory is prepended to the executable search path for future child processes.

Notes and limitations

  • New child processes inherit the variable; already running services do not.
  • Do not store real secrets in command history. For persistent configuration, use the appropriate shell startup file or service configuration.

Common questions and troubleshooting

Why is my variable absent after reconnecting?

The export applied to the previous shell. Persistent configuration requires the appropriate startup or service environment configuration.

Can changing PATH create a security problem?

Yes. Earlier directories take precedence and may supply an unexpected executable. Add only trusted locations and quote variable expansions.

Further help

Options vary by version and distribution. Check the installed documentation with this command: help export.