Solved which(1): Why would which -a -s return command not found?

I had trouble searching for this one because of the word "which"; so, I apologize if the answer is here.

When I give the command which -s PROGRAM_NAME or which -a PROGRAM_NAME, I see responses like: -a: Command not found.

The man page suggests that I would be able to get which to use args like -a -s. Am I doing something wrong here? Or, does the man page not match up with the which(1) provided? I see there is a warning that some shells may have their own which. When using csh, I see this error. If there's a difference in the "which" I don't know how to discover it.

Using FreeBSD 12.1-RELEASE-p5 on one machine and FreeBSD 12.1-RELEASE-p10 on another. Seeing this kind of behavior in both places. My goal would be to pick up the return code from which to use it in a script as a validation test. Any advice you might give could be helpful. Thanks.
 
The man page you give is from /usr/bin/which.
The which command is integrated in some shells and there is no option to specify.

Some shells may provide a builtin which command which is similar or iden-
tical to this utility. Consult the builtin(1) manual page.
So, if you want these options, type: /usr/bin/which
 
OK, I was able to do this simply enough. In bash, in a script testing if a program name assigned to $PROGRAM could be found:

Code:
if ! which -s $PROGRAM  
26 then
27         echo "Program not found."
28         exit;
29 fi

Using the point about absolute path, above, perhaps the problem could be solved like:
Code:
/usr/bin/which -s $PROGRAM; echo $?
or similar.
 
env which is another option, especially if you come back to a script several months later and wonder what a backslash is doing in front of commands:
Code:
csh% which
which: Too few arguments.
csh% env which
usage: which [-as] program ...
If you're using an interactive shell that uses sh syntax (e.g. bash, dash, ksh, zsh), command -V is useful in interactive sessions:
Code:
sh$ command -V which
which is /usr/bin/which
sh$ command -V cd
cd is a shell builtin
sh$ command -V ll
ll is an alias for ls -laFo
sh$ foo() {}; command -V foo
foo is a shell function
 
Back
Top