Is `command -v` option required in a POSIX shell? Is posh compliant with POSIX?

前端 未结 2 1003
青春惊慌失措
青春惊慌失措 2021-01-18 18:28

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

相关标签:
2条回答
  • 2021-01-18 19:00

    See the [UP] margin code next to the definition of -v. Per the list of margin code notations (emphasis added):

    [UP] User Portability

    The functionality described is optional.

    Where applicable, utilities are marked with the UP margin legend in the SYNOPSIS section. Where additional semantics apply to a utility, the material is identified by use of the UP margin legend.

    Thus, it's black-letter POSIX: This functionality is optional.

    0 讨论(0)
  • 2021-01-18 19:14

    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 (as amended in 2013) does not mark any part of the specification of command with 'User Portability' subset:

    Synopsis

    command [-p] command_name [argument...]
    
    command [-p][-v|-V] command_name
    

    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.

    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.

    When the -v or -V option is used, the command utility shall provide information concerning how a command name is interpreted by the shell.

    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.

    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.

    0 讨论(0)
提交回复
热议问题