The export command
The export command sets an environment variable that programs started from this…
The export command sets an environment variable that programs started from this shell can read, as in export EDITOR=nano.
Taught in Intermediate, lesson 24; more in Ninja
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.
Usage
export NAME=VALUE export NAME
Set an environment variable. Sets a variable and marks it for export, so programs started from this shell can read it. With no arguments it lists the exported variables. Read a variable back with $NAME, as in echo $NAME.
How to use export
Set a variable
No spaces around =. Read it back with a dollar sign in front of the name.
export GREETING=hello && echo $GREETINGhello
List exported variables
export | head -n 4declare -x EDITOR="nano" declare -x HOME="/home/learner" declare -x LANG="en_US.UTF-8" declare -x LOGNAME="learner"
Add a folder to PATH
PATH is the list of folders the shell searches for programs, separated by colons.
export PATH="$HOME/bin:$PATH" && echo $PATH/home/learner/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
More examples
export EDITOR=nanoecho $EDITORnano
Questions about export
What is the difference between VAR=value and export VAR=value?
Both set the variable in this shell. export also passes it to programs and scripts you start from here.
How do I keep a variable for next time?
Add the export line to ~/.bashrc, then run source ~/.bashrc.
Learn it step by step
Related commands
Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.