export
进程与系统
用法
export VAR=value给变量打上标记,让子进程能继承它;它随这个 shell 一起消失,想长期保留就写进 ~/.bashrc 或 ~/.zshrc,而只写 `VAR=x` 不加 export,你启动的程序看不到它。
常用选项
| 选项 | 含义 |
|---|---|
| VAR=value | Set it and mark it for export in one step. |
| -p | List everything currently exported. |
| -n <VAR> | Keep the variable but stop passing it to child processes. |
| -f <fn> | Export a shell function as well (bash). |
示例
export PATH="$HOME/bin:$PATH"Put your own bin directory first for this session.
export AWS_PROFILE=stagingEvery command started afterwards in this shell sees it.
看什么在跑、什么在吃机器。先弄清是什么,再决定杀不杀。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. export 是做什么的?
给变量打上标记,让子进程能继承它;它随这个 shell 一起消失,想长期保留就写进 ~/.bashrc 或 ~/.zshrc,而只写 `VAR=x` 不加 export,你启动的程序看不到它。
Q. 怎么写?
export VAR=value —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 4 个,完整列表在 man export。这条命令属于进程与系统。
相关命令
man 手册: man export