export Command
The export command sets environment variables and makes them available to child processes. It converts shell variables into environment variables that can be inherited by subprocesses.
Syntax
Description
The export command is a shell builtin that marks variables for automatic export to the environment of subsequently executed commands. It's essential for making variables available to child processes.
Key features:
- Convert shell variables to environment variables
- Make variables available to child processes
- Display all exported variables
- Set and export variables in one command
- Essential for shell scripting and configuration
Common Options
| Option | Description |
|---|---|
-p |
Display all exported variables in a format that can be reused |
-n |
Remove the export property from variables |
-f |
Export functions instead of variables |
Examples
Export a new variable
Creates and exports a new environment variable
Export existing shell variable
Exports an existing shell variable to the environment
Display all exported variables
Shows all currently exported environment variables
Display in reusable format
Shows exported variables in a format that can be sourced
Export PATH variable
Adds a directory to the PATH environment variable
Export multiple variables
Exports multiple variables in one command
Remove export property
Removes the export property from a variable (keeps it as shell variable)
Export with command substitution
Exports a variable with the result of command substitution
Export for current session
Sets common environment variables for the current session
Export function
Exports a shell function to child processes
Common Use Cases
Setting development environment
Common setup for Java development environment
Database configuration
Setting database connection parameters
Application configuration
Common application environment variables