export
Set environment variables for child processes
TLDR
Set an environment variable
Append a pathname to the environment variable $PATH
SYNOPSIS
export [-fn] [name[=word] ... ]
export -p
PARAMETERS
-f
Treat function names as arguments; export functions instead of variables
-n
Remove export attribute from variables (make them local)
-p
Print all exported names and values in a format usable as shell input
name[=word]
Variable name to export; optional =word sets or overrides its value
DESCRIPTION
The export command is a shell builtin that marks variables (or functions) for export to the environment of child processes. When a variable is exported, its name and value are passed to subsequently executed commands, scripts, or subshells, allowing them to inherit and use these settings.
Without export, variables remain local to the current shell session. Common use cases include setting PATH, HOME, or custom variables like EDITOR.
For instance:
export PATH=/usr/local/bin:$PATH
This prepends /usr/local/bin to the PATH for all child processes.
export can also list all exported variables with -p, remove the export attribute (making it local again) with -n, or handle function names with -f. Multiple variables can be exported at once: export VAR1=value1 VAR2=value2.
Exported values are strings; complex data structures require serialization. Changes do not affect the parent shell, only children. This ensures environment isolation while enabling configuration propagation.
CAVEATS
Export affects only child processes, not parent shell. Functions exported with -f are copied by value. Infinite recursion possible if functions reference themselves during export.
EXAMPLES
export -p | grep PATH — List exported PATH.
export -n DISPLAY — Stop exporting DISPLAY.
foo() { echo hello; }; export -f foo — Export function foo.
IN SCRIPTS
Use in #!/bin/sh shebangs to set env for subprocesses: export LC_ALL=C
HISTORY
Originated in Bourne shell (1977) by Stephen Bourne at Bell Labs. Adopted in POSIX.1-1988, with enhancements like -f and -n in Bash (1989) and ksh.


