The export
command is used to set environment variables in a Linux or Unix shell. Environment variables are variables that are set in the shell and are available to all processes that are started from the shell.
To set an environment variable, you can use the export
command followed by the variable name and value. For example, to set the FOO
variable to bar
, you can use the following command:
export FOO=bar
This will set the FOO
variable to bar
for the current shell session. To make the change permanent, you can add the export
line to your Bash profile file, such as ~/.bashrc
or ~/.bash_profile
.
You can also set multiple variables at once by separating them with a space. For example:
export FOO=bar BAZ=qux
This will set the FOO
variable to bar
and the BAZ
variable to qux
.
To view the current value of an environment variable, you can use the echo
command. For example:
echo $FOO
This will print the value of the FOO
variable to the console.
To unset an environment variable, you can use the unset
command followed by the variable name. For example:
unset FOO
This will unset the FOO
variable and remove it from the environment.
Keep in mind that environment variables are specific to the shell and are not inherited by child processes. If you want to set an environment variable for a child process, you can use the env
command to set the variable in the child process's environment.
For example, to start a new shell with the FOO
variable set to bar
, you can use the following command:
env FOO=bar bash
This will start a new Bash shell with the FOO
variable set to bar
. The FOO
variable will not be set in the parent shell.