The export
command in Linux is used to set environment variables. Environment variables are dynamic values that can be accessed by processes or programs running on the system. The export
command allows you to define or modify environment variables and make them available to child processes.
Here’s an overview of how to use the export
command:
- Basic Usage:
To set an environment variable, use theexport
command followed by the variable name and its value. For example:
export MY_VARIABLE="Hello, World!"
This command sets the MY_VARIABLE
environment variable to the value “Hello, World!”.
- Making Variables Available to Child Processes:
By default, environment variables are only accessible by the current shell process. If you want to make them available to child processes, including scripts or programs executed from the current shell, you need to use theexport
command. - Examples:
- Setting an environment variable:
export MY_VARIABLE="OpenAI"
This command sets theMY_VARIABLE
environment variable to the value “OpenAI”. Subsequent child processes can access this variable. - Modifying an existing environment variable:
export PATH="$PATH:/new/directory"
This command appends the/new/directory
to the existingPATH
environment variable, allowing the shell and child processes to search for executables in that directory. - Unsetting an environment variable:
export MY_VARIABLE=
This command unsets or clears the value of theMY_VARIABLE
environment variable, making it empty. Subsequent child processes will not have access to this variable.
The export
command is often used in shell scripts to define environment variables that need to be accessed by other commands or child processes. It allows for dynamic configuration and customization of the environment for various applications and programs.
Note that environment variables set using the export
command are specific to the current shell session. They are not persistent across different sessions or system reboots. If you want to set environment variables permanently, you can add the export
commands to your shell’s configuration file, such as .bashrc
or .profile
.
For more information about the export
command and environment variables in Linux, you can refer to the manual page by typing man export
or man environ
in your terminal.