Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

posix

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?

like image 574
Lone Learner Avatar asked Jan 03 '16 02:01

Lone Learner


People also ask

What shells are POSIX compliant?

Some popular shell languages are POSIX-compliant (Bash, Korn shell), but even they offer additional non-POSIX features which will not always function on other shells. The commands test expression is identical to the command [expression] . In fact, many sources recommend using the brackets for better readability.

What are POSIX commands?

POSIX is shorthand for Portable Operating System Interface. It is an IEEE 1003.1 standard that defines the language interface between application programs (along with command line shells and utility interfaces) and the UNIX operating system.


2 Answers

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.

like image 143
Jonathan Leffler Avatar answered Sep 21 '22 19:09

Jonathan Leffler


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.

like image 32
Charles Duffy Avatar answered Sep 21 '22 19:09

Charles Duffy