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