Re: Public service announcement about Policy 10.4
Marco d'Itri wrote:
> Andreas Metzler wrote:
> > Thomas Hood wrote:
> > > Is there anything else which dash supports but posh does not?
> > command -v
>
> Which is the well known which(1) replacement, and basically mandatory
> in a sane Debian shell. I keep wondering why people bother with posh.
"command -v" is optional under POSIX. Furthermore It behaves
differently in different shells.
$ bash
$ command -v foo
bash: command: foo: not found
$ echo $?
1
$ dash
$ command -v foo
$ echo $?
127
$ posh
$ command -v foo
command: invalid option -- v
$
(Some would argue that this violates 10.1, or should do.)
It is not even useful as a which(1) replacement. Whereas "which"
prints the pathname of the first executable file on the PATH,
"command -v" prints the pathname of the first executable file on the
PATH _or_ the pathname of the first non-executable file on the PATH.
In any case, there is no need to substitute anything for "which".
For these reasons the use of "command -v" should be avoided in
/bin/sh scripts and I would say that posh is right to omit it.
--
Thomas Hood
Reply to: