首頁·終端機命令

env

行程與系統

用法

env [VAR=value] [command]

印出整個環境變數表,或者帶上額外變數執行一條命令;那些變數只對這一次執行生效,你的 shell 裡不留下任何東西。

常用選項

選項含義
envWith no arguments, print the whole environment.
VAR=value <command>Run the command with that variable added, for this run only.
-iStart from an empty environment, inheriting nothing.
-u <VAR>Unset one variable for the child process.

範例

env | sort | grep -i proxy

Find the proxy variables that are breaking a download.

env NODE_ENV=production node app.js

Set a variable for one run without touching your shell.

env -i bash --noprofile --norc

A shell with nothing inherited, for reproducing a cron failure.

看什麼在跑、什麼在吃機器。先弄清是什麼,再決定殺不殺。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. env 是做什麼的?

印出整個環境變數表,或者帶上額外變數執行一條命令;那些變數只對這一次執行生效,你的 shell 裡不留下任何東西。

Q. 怎麼寫?

env [VAR=value] [command] —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 4 個,完整列表在 man env。這條命令屬於行程與系統。

相關命令

man 手冊: man env