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

前端 未结 2 1018
青春惊慌失措
青春惊慌失措 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条回答
  •  Happy的楠姐
    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.

提交回复
热议问题