CODE/2022-09-19

Using export to Set Environment Variables in Linux

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.
COMPANION ESSAYS / 思想脉络与互照篇目
同卷深读2026-05-22 ·

Installing Python 3 Alongside System Python on CentOS 7

同属「系统工程卷」脉络衍生思考与工程推演推演阅读 →
跨界互照2026-08-22 ·

我的书架:03|金融经管:经济运行、金融体系与企业治理

我的书架:03|金融经管:经济运行、金融体系与企业治理

跨领域对照思辨 · 从「思想随笔」视界互为印证推演阅读 →
RELATED INDEX / 相关阅读索引
柯航hang.ke·© 2014—2026
CC BY-NC 4.0·