How to make `man` work for shell builtin commands and keywords?

The help command when is used with -m option can display information about builtin commands in pseudo-manpage format. For example:

help -m cd | less

will display information about cd command in a format almost exactly like in a manual page.

Starting from this command you can wrap man command in one function in your .bashrc file as follow:

man () {
    case "$(type -t -- "$1")" in
    builtin|keyword)
        help -m "$1" | sensible-pager
        ;;
    *)
        command man "$@"
        ;;
    esac
}

After this man will work also for all shell builtin commands and keywords. For example:

man :

will display:

NAME
    : - Null command.

SYNOPSIS
    :

DESCRIPTION
    Null command.

    No effect; the command does nothing.

    Exit Status:
    Always succeeds.

SEE ALSO
    bash(1)

IMPLEMENTATION
    GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)
    Copyright (C) 2011 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

man bash-builtins

This contains help snippets for the builtin commands, albeit in a slightly more condensed format than the help equivalent.


You can install manual pages about using a POSIX system for development as,

sudo apt-get install manpages-posix-dev

It will provide man pages for shell builtins.

$ type cd
cd is a shell builtin

Now try,

$ man cd
CD(P)                      POSIX Programmer's Manual                      CD(P)

NAME
   cd - change the working directory

SYNOPSIS
   cd [-L | -P] [directory]


...