在POSIX shell中是否需要使用command -v选项? posh符合POSIX吗? [英] Is `command -v` option required in a POSIX shell? Is posh compliant with POSIX?
问题描述
我正在使用 posh 来测试要在任何POSIX上成功运行的shell脚本兼容的外壳.这样做时,我发现posh不支持command -v
选项. type
都不是.
I am using posh to test my shell script that I want to run successfully on any POSIX compliant shell. While doing so, I found that the command -v
option is not supported in posh. Neither is type
.
我知道不支持type
,因为POSIX不需要它.在 https://bugs.debian.org/cgi上对此进行了讨论. -bin/bugreport.cgi?bug = 397601#10 .
I understand that type
is not supported because it is not required by POSIX. This is discussed at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=397601#10.
"type"是X/Open扩展名;注意POSIX中的XSI标记 标准.由于POSIX或debian政策并不需要,因此请使用posh 没有实现.
"type" is an X/Open extension; note the XSI marking in the POSIX standard. Since it is not required by POSIX or by debian policy, posh doesn't implement it.
http://pubs.opengroup.org/onlinepubs/009695399/utilities/type.html 确认这一点.请参见提要中的[XSI]
边距代码.
http://pubs.opengroup.org/onlinepubs/009695399/utilities/type.html confirms this. See the [XSI]
margin code in the synopsis.
但是我不明白为什么posh不支持command -v
选项.
But I fail to understand why command -v
option is not supported in posh.
有人提到command -v
是 https:/可选的/bugs.debian.org/cgi-bin/bugreport.cgi?bug=218530#131 .
根据以下说明,"command -v"是可选功能 http://www.opengroup.org/onlinepubs/009695399/utilities/ 只是提一下.
And "command -v" is an optional functionality according to http://www.opengroup.org/onlinepubs/009695399/utilities/ just to mention it.
但是我无法在 http://pubs.opengroup上确认这一点. org/onlinepubs/009695399/utilities/command.html .
如果不是,posh
是否与POSIX不兼容?
If not, is posh
is not compliant with POSIX?
推荐答案
这取决于它们兼容的POSIX版本.在POSIX 2004资料中, command
在其中具有-v
和-V
选项.标准的可选部分-用户可移植性"子集.
It depends on which version of POSIX they're compatible with. In the POSIX 2004 material, command
has the -v
and -V
options in an optional part of the standard — the 'User Portability' subset.
POSIX 2008(2013年修订)未标记 command
具有用户可移植性"子集:
POSIX 2008 (as amended in 2013) does not mark any part of the specification of command
with 'User Portability' subset:
简介
command [-p] command_name [argument...]
command [-p][-v|-V] command_name
说明
command
实用程序将使Shell将参数视为简单命令,从而抑制了Command Search and Execution,项目1b中描述的Shell函数查找.
DESCRIPTION
The command
utility shall cause the shell to treat the arguments as a simple command, suppressing the shell function lookup that is described in Command Search and Execution, item 1b.
如果command_name
与其中一个特殊内置实用程序的名称相同,则在特殊内置实用程序开头的枚举列表中的特殊属性将不会出现.在其他各个方面,如果command_name
不是函数的名称,则command
的效果(无选项)应与省略command
相同.
If the command_name
is the same as the name of one of the special built-in utilities, the special properties in the enumerated list at the beginning of Special Built-In Utilities shall not occur. In every other respect, if command_name
is not the name of a function, the effect of command
(with no options) shall be the same as omitting command
.
使用-v
或-V
选项时,command
实用程序应提供有关外壳如何解释命令名的信息.
When the -v
or -V
option is used, the command
utility shall provide information concerning how a command name is interpreted by the shell.
2008/2013版本中未列出任何可选标志.在较早的(2004)标准中,-v
和-V
选项是用户可移植性"子集的一部分,而不是核心的一部分.
There are no optional flags listed in the 2008/2013 version. In the older (2004) standard, the -v
and -V
options were part of the 'user portability' subset, not part of the core.
因此,如果他们希望遵守已有十多年历史的标准,则不需要-v
或-V
;如果他们希望符合当前标准(已使用5年以上),则应支持这些选项.
So, if they want to conform to the standard that is more than a decade old, there's no need for -v
or -V
; if they want to conform to the current standard (which is more than 5 years old), these options should be supported.
这篇关于在POSIX shell中是否需要使用command -v选项? posh符合POSIX吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!