Can I get individual man pages for the bash builtin commands?
help read
help read | less
In zsh:
run-help read
or type read something
and press M-h
(i.e. Alt+h
or ESC h
).
If you want to have a single man
command so as not to need to know whether the command is a built-in, define this function in your ~/.bashrc
:
man () {
case "$(type -t "$1"):$1" in
builtin:*) help "$1" | "${PAGER:-less}";; # built-in
*[[?*]*) help "$1" | "${PAGER:-less}";; # pattern
*) command -p man "$@";; # something else, presumed to be an external command
# or options for the man command or a section number
esac
}
Try this:
bashman () { man bash | less -p "^ $1 "; }
You may have to hit n a couple of times to get to the actual command instead of a paragraph that happens to have the command name as the first word.
Explanation: this pipes the entire output of man bash
, i.e. bash's entire man page (which is a huge document, and has subsections explaining each bash builtin command) to the reading program less
. less' -p
flag stands for "pattern"; what it does is automatically scroll to the first point in the input text that matches the pattern. The pattern here is a regex which matches "The start of a line (^
), followed by a specific number of spaces, followed by ..." – and here, bash inserts the first argument provided to the bashman
function, because bash sees the special $1
token (which means "the first argument") in a string delimited with double-quotes (single quotes would tell bash that you literally mean the characters $1
). So, if you run bashman cd
, you will effectively be searching for any line in bash's man page with starts with a bunch of spaces, then the string "cd". Because there might be other points in bash's entire man page that also match this pattern besides the actual heading of the section that explains, eg., "cd", this function may not actually take you to the correct part of the bash man page.