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