env

プロセスとシステム

書き方

env [VAR=value] [command]

環境変数をすべて表示するか、変数を足してコマンドを一つ動かします。その変数はその一回の実行にだけ付き、シェルには何も残りません。

よく使うオプション

オプション意味
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 は何をしますか。

環境変数をすべて表示するか、変数を足してコマンドを一つ動かします。その変数はその一回の実行にだけ付き、シェルには何も残りません。

Q. どう打ちますか。

env [VAR=value] [command] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは4個です。全部は man env にあります。このコマンドはプロセスとシステムの仲間です。

関連するコマンド

man ページ: man env