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
- Basic Usage:
To set an environment variable, use the
exportcommand 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 the
- Setting an environment variable:
export MY_VARIABLE="OpenAI"This command sets the
MY_VARIABLEenvironment 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/directoryto the existing
PATHenvironment variable, allowing the shell and child processes to search for executables in that directory.
- Unsetting an environment variable:
This command unsets or clears the value of the
MY_VARIABLEenvironment variable, making it empty. Subsequent child processes will not have access to this variable.
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
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.