How can I easily see the man page for builtin shell commands?

Solution 1:

Perhaps you like to have some wrapper function which skips directly to the builtin:

man -P "less +/\ \ \ pushd" bash

-P tells man to use less as pager (probably the default on most systems), but pass directly a search to it. You need to add some blanks before the search string to skip hits in text and go to the description of the command.

For convenience make a function out of it and put it into your ~/.bashrc:

function manbash {
   man -P "less +/\ \ \ $1" bash
}

and use it like manbash pushd.


Another possibility is to use the bash builtin help:

$ help pushd
pushd: pushd [-n] [+N | -N | dir]
Add directories to stack.

Adds a directory to the top of the directory stack, or rotates
the stack, making the new top of the stack the current working
directory.  With no arguments, exchanges the top two directories.

Options:
[...]

Solution 2:

Would man bash-builtins be more helpful? Also, you can search within man pages by hitting / and entering your search term.

Solution 3:

less also recognizes start-of-line anchor ^ and greedy matching operator *.

man -P "less '+/^ *'pushd" bash

manbb() {
   man -P "less '+/^ *'${1}" bash
}

manbb pushd