Scroll to navigation

ENV(1) 使用者命令 ENV(1)

名稱

env - 在重建的環境中執行程式

概述

env [選項]... [-] [名稱=值]... [命令 [引數列表]...]

描述

在環境中將每個指定名稱的環境變數設為指定的值,並執行給定命令。

必選引數對長短選項同時適用。

不帶環境變數啟動
-0, --null
使每行輸出以 NUL 字元結束,不新增換行符
從環境中移除指定環境變數
將工作目錄修改為指定的目錄名稱
處理並將 S 字串分割為多個引數;用於向 shebang 行傳遞多個引數
阻擋向指定命令傳遞指定的訊號
將對指定訊號的處理方式重置為預設方式
將對指定訊號的處理方式設定為什麼都不做
向標準錯誤輸出非預設的訊號處理方式
為每個處理流程輸出詳細資訊
顯示此幫助資訊並退出
顯示版本資訊並退出

單獨的“-”隱含選項 -i。如果沒有給定命令,則輸出重建後的環境。

引數中的訊號可以是類似 'PIPE' 這樣的訊號名稱,也可以是如 '1' 這樣的訊號編碼。所有已知訊號均包括其中。如需指定多個訊號,可以使用半形逗號隔開。

選項

-S/--split-string 在指令碼中的用法

-S 選項可以在指令碼中指定多個引數。例如,執行一個名為 1.pl的指令碼,其第一行如下所示:

#!/usr/bin/env -S perl -w -T
...

將會執行 perl -w -T 1.pl .

如果不加 '-S' 引數,指令碼可能執行失敗並輸出以下錯誤:

/usr/bin/env: 'perl -w -T': 沒有那個檔案或目錄

請閱讀完整文件以瞭解更多細節。

--default-signal[=訊號] 的用法

This option allows setting a signal handler to its default action, which is not possible using the traditional shell trap command. The following example ensures that seq will be terminated by SIGPIPE no matter how this signal is being handled in the process invoking the command.

sh -c 'env --default-signal=PIPE seq inf | head -n1'

注意

POSIX 的 exec(2) 手冊頁有以下內容:

"many existing applications wrongly assume that they start with certain signals set to the default action and/or unblocked.... Therefore, it is best not to block or ignore signals across execs without explicit reason to do so, and especially not to block signals across execs of arbitrary (not closely cooperating) programs."

作者

由 Richard Mlynarik、David MacKenzie 和 Assaf Gordon 編寫。

報告錯誤

GNU coreutils 的線上幫助: <https://www.gnu.org/software/coreutils/>
請向 <https://translationproject.org/team/zh_CN.html> 報告翻譯錯誤。

版權

請向 <https://translationproject.org/team/zh_CN.html> 報告翻譯錯誤。
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

參見

sigaction(2), sigprocmask(2), signal(7)

完整文件請見: <https://www.gnu.org/software/coreutils/env>
或者在本地使用: info '(coreutils) env invocation'

本頁面中文版由中文 man 手冊頁計劃提供。
中文 man 手冊頁計劃:https://github.com/man-pages-zh/manpages-zh

2020年三月 GNU coreutils 8.32