Thursday, November 12, 2009

The "help" Command, And Other Aids

In his latest Command-Line Kung Fu post, Hal Pomeranz talks about places to get help on Unix systems and their kin. (Technically, that's "their latest post," but his co-conspirators write about Microsoft stuff, which I don't care about.)

Hal concentrates on man(1), info(1), and apropos(1), and the --help flag. Good places to start, but there are other things worth mentioning.

So I will.

locate(1) is quite handy. I often find myself hunting for commands that don't have man entries of any kind, and are installed someplace bizarre. Once I find them, /path/to/command --help often tells me enough. If not, but they're in some special directory, there's sometimes a README or examples that do the trick.

Another frequent stop is the web. If command --help doesn't tell me what I want to know, the web's more likely to have a man page than my machine is. I'll now usually go there first.

If it's not an executable? How about type?
$ type ls
ls is aliased to `ls --color=auto'
$ type cdjob
cdjob is a function
cdjob ()
{
local d;
: ${1:?"usage $FUNCNAME %N"};
d=$(jobs $1 | perl -lane 'print "cd $1" if m/.*\(wd: (.*)\).*/');
test "$d" && eval $d
}
And what's type?
$ type type
type is a shell builtin
For information about type, do we have to pour through the zillion-page, bash man page? On-line?

Nope. Watch:
$ man type
No manual entry for type
$ type type
type is a shell builtin
$ help type
type: type [-afptP] name [name ...]
Display information about command type.
For each NAME, indicate how it would be interpreted if used as a
command name.
Options:
-a display all locations containing an executable named NAME;
includes aliases, builtins, and functions, if and only if
the `-p' option is not also used
-f suppress shell function lookup
-P force a PATH search for each NAME, even if it is an alias,
builtin, or function, and returns the name of the disk file
that would be executed
-p returns either the name of the disk file that would be executed,
or nothing if `type -t NAME' would not return `file'.
-t output a single word which is one of `alias', `keyword',
`function', `builtin', `file' or `', if NAME is an alias, shell
reserved word, shell function, shell builtin, disk file, or not
found, respectively
Arguments:
NAME Command name to be interpreted.
Exit Status:
Returns success if all of the NAMEs are found; fails if any are not found.
typeset: typeset [-aAfFilrtux] [-p] name[=value] ...
Set variable values and attributes.
Obsolete. See `help declare'.
Yes, there's really a help command. It gives help about shell builtins.

If I don't even have the command? (If, for example, it's part of someone else's script I've pulled down from somewhere?)

Here's what I get out of bash when I invoke als(1) on my Ubuntu box.
$ als
The program 'als' is currently not installed. You can install it by typing:
sudo apt-get install atool
als: command not found
Not help with the command, okay, but help getting it so I can then get help with it.

What would you pay? But wait. There's more.

If I guess at a command but mis-type it?
$ las
No command 'las' found, did you mean:
Command 'als' from package 'atool' (universe)
Command 'ls' from package 'coreutils' (main)
Command 'lfs' from package 'lustre-utils' (universe)
Command 'lms' from package 'lms' (universe)
Command 'les' from package 'atm-tools' (universe)
Command 'last' from package 'sysvinit-utils' (main)
Command 'laps' from package 'epix1' (universe)
Command 'lvs' from package 'lvm2' (main)
Command 'cas' from package 'amule-adunanza-utils' (universe)
Command 'cas' from package 'amule-utils' (universe)
Command 'as' from package 'binutils' (main)
Command 'ras' from package 'ras' (universe)
Command 'kas' from package 'openafs-kpasswd' (universe)
Command 'lat' from package 'lat' (universe)
las: command not found
I think that's nice. And I can use apt-cache show to tell me what each package is.




No comments: