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

command linemanpage

I use the man command all the time when I want to get information about a specific command. But this doesn't help me too much when that specific command is a shell builtin. For example:

man cd


No manual entry for cd

My question is: it is possible to make man also work for all shell builtin commands (like cd, alias, history, etc.), and keywords (like if, while, [[, {, etc.)?

Best Answer

  • 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
            help -m "$1" | sensible-pager
            command man "$@"

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

    man :

    will display:

        : - Null command.
        Null command.
        No effect; the command does nothing.
        Exit Status:
        Always succeeds.
        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>