Linux export command

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:

  1. Basic Usage:
    To set an environment variable, use the export 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!”.

  1. 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 export command.
  2. Examples:
  • Setting an environment variable: export MY_VARIABLE="OpenAI" This command sets the MY_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 existing PATH 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 the MY_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.