I think you're looking for man
command.
Try doing man mkdir
and look for what the -p switch does. You can use vim style searching here.
Use man man
for more info on how to use man
command.
$_
will work in (at least) interactive dash
, bash
, zsh
, ksh
(though apparently not in a conditional statement as requested) and mksh
shells. Of those - to my knowledge - only bash
and zsh
will also populate it in a scripted shell. It is not a POSIX parameter - but is fairly portable to any modern, interactive shell.
For a more portable solution you can do:
command -p sudo ...
eval '[ "$?" = 127 ] || exit '"$?"
Which basically allows you to expand the initial value for $?
into the tail of the script before ever even testing its value at its head.
But anyway, since you appear to be testing whether or not the command sudo
can be found in the shell's builtin -p
portable path string with command
, I would think you could go at it a litte more directly. Also, just to be clear, command
won't test for the location of any arguments to sudo
- so it is only sudo
- and nothing it invokes - which is relevant to that return value.
And so anyway, if that is what you're trying to do:
command -pv sudo >/dev/null || handle_it
command -p sudo something or another
...would work just fine as a test without any chance of errors in the command sudo
runs returning in such a way that might skew the results of your test.
Best Answer
Source code is going to be your best bet. You can in a pinch use the command
strings
to get some basic ideas about a binary and text that it may contain.Example
Here are the first 20 lines of the output. These are the lines that contain the string "error" in them.