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