6

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.

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" 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 confirms this. See the [XSI] margin code in the synopsis.

But I fail to understand why command -v option is not supported in posh.

Some mentions that command -v is optional at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=218530#131.

And "command -v" is an optional functionality according to http://www.opengroup.org/onlinepubs/009695399/utilities/ just to mention it.

But I am unable to confirm this at http://pubs.opengroup.org/onlinepubs/009695399/utilities/command.html. Can you see anything here that indicates that -v option is optional in command?

If not, is posh is not compliant with POSIX?

Lone Learner
  • 18,088
  • 20
  • 102
  • 200

2 Answers2

7

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.

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
2

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.

Community
  • 1
  • 1
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • 3
    Only in the 2004 edition — it is not optional in the 2008/2013 edition. Note the part at the top of the [`command`](http://pubs.opengroup.org/onlinepubs/009695399/utilities/command.html) description which says (in bright red) 'A newer edition of this document exists [here](http://pubs.opengroup.org/onlinepubs/9699919799/)'. – Jonathan Leffler Jan 03 '16 at 02:51