In Bash,
export marks variables for inclusion in the environment of subsequently launched child processes. It does not modify the parent shell or other existing processes.Export a variable
bash_snippet
Bash · 2 lines|
| export APP_MODE="development" |
| printf '%s\n' "$APP_MODE" |
To inspect exported variables, run
export -p or env. To stop exporting a Bash variable without deleting it, use export -n APP_MODE; use unset APP_MODE to remove it from the current shell.Add a directory to PATH
bash_snippet
Bash · 1 line|
| export PATH="$PATH:/opt/example/bin" |
PATH is case-sensitive. Check directory ownership and permissions before adding a directory to it.Persist the setting
Add the export to the appropriate user startup file, such as
~/.bashrc for interactive non-login Bash or ~/.bash_profile for a login shell. Startup behavior depends on how the shell is launched. Start a new shell or source the file to apply its contents to the current shell.For system-wide login-shell settings, an administrator can use an appropriate
/etc/profile.d/ file. Review the system's existing configuration and avoid storing secrets in shared startup files.✦ 卷终 · 柯航存卷 ✦