Quick take: The export command marks a shell variable as an environment variable so child processes inherit it: export PATH=$PATH:/opt/bin. Without export, a variable stays local to the current shell.
Introduction
Variables in the shell come in two kinds: ordinary shell variables, visible only to the current shell, and environment variables, inherited by every program the shell launches. The export command promotes a variable to the environment, which is how you configure programs through variables like PATH, EDITOR, and application-specific settings.
Syntax
The basic syntax of the export command is:
export NAME=VALUE
export NAMECommon Options and Parameters
The most useful options and parameters for the export command:
| Option | Description |
|---|---|
| export NAME=VALUE | Set a variable and export it in one step. |
| export NAME | Export an existing shell variable. |
| export -p | List all exported variables. |
| export -n NAME | Stop exporting a variable (keep it local). |
| printenv / env | Display the current environment. |
Practical Examples
Real export commands you can run today:
# Set and export a variable
export EDITOR=vim
# Add a directory to PATH
export PATH=$PATH:/opt/myapp/bin
# Export an existing variable
MYVAR=hello; export MYVAR
# List exported variables
export -p
# Show the whole environment
printenv
# Make it permanent (add to ~/.bashrc)
echo 'export EDITOR=vim' >> ~/.bashrcTips and Best Practices
- A variable set without
exportis visible only to the current shell; child programs will not see it until you export it. - To make an environment variable permanent, add the
exportline to~/.bashrc(per user) or/etc/environment(system-wide). - When extending
PATH, always include the existing value (export PATH=$PATH:/new) so you do not wipe it out.
Final Thoughts
export is how variables reach the programs you run — promoting a shell variable into the environment that child processes inherit. Use it for PATH, editor preferences, and app configuration, always preserving existing values when appending. Add the lines to ~/.bashrc to make them stick, and use printenv to inspect the result.
FAQ: export Command in Linux
What does export do in Linux?+
export marks a shell variable as an environment variable so that child processes started from the shell inherit it. Without export, the variable is only visible in the current shell.
How do I add a directory to PATH?+
Use export PATH=$PATH:/new/directory, which appends to the existing PATH. Add the line to ~/.bashrc to make it permanent. Always include $PATH so you do not replace the current value.
What is the difference between a shell variable and an environment variable?+
A shell variable exists only in the current shell. An environment variable, created with export, is passed to every program the shell launches. Use export when a program needs to read the value.
How do I make an environment variable permanent?+
Add the export line to ~/.bashrc or ~/.profile for your user, or to /etc/environment for all users. Then source the file or open a new shell.
How do I see all environment variables?+
Run printenv or env to list the full environment, or export -p to list exported variables with their values.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support