[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Public service announcement about Policy 10.4



Andreas Metzler wrote:
> Thomas Hood <jdthood@aglu.demon.nl> wrote:
> [command -v]
> > 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.
> 
> s/_or_/or - if there is matching executable at all in PATH -/


Yes, my statement wasn't worded very well.  "command -v" prints the
pathname of the first executable file on the PATH that matches its
argument, if there is such a file; otherwise it prints the pathname
of the first non-executable file on the PATH that matches its argument,
if there is such a file; otherwise it prints nothing (or, in bash's
case, it prints an error message on stderr).

 
> FWIW I am using command -v in one of my maintainerscripts, as I needed
> to check whether $command which (currently) is an alias of shell-
> function exists:


That is indeed the shortcoming of which(1): it can't "see" shell
functions; whereas the "command" builtin can.

-- 
Thomas Hood



Reply to: