The export
command is used in Linux/Unix to set environment variables, which are used to store values that can be referenced in various shell commands and scripts.
To set an environment variable using export
, simply type the following in your terminal:
export VARNAME=value
Replace VARNAME
with the name of the environment variable, and value
with the desired value. For example, to set an environment variable named MY_VAR
to the value hello
, you would run the following:
export MY_VAR=hello
Once you’ve set an environment variable using export
, you can access its value in any script or shell session by using $VARNAME
. For example:
echo $MY_VAR
This will display the value of the MY_VAR
environment variable, which is hello
in this example.
It’s important to note that environment variables set with export
are only accessible in the current shell session. If you want to persist an environment variable across multiple shell sessions or make it available to other users, you will need to set it in your shell profile file, such as ~/.bashrc
or ~/.bash_profile
.