Friday, May 3, 2024
71
rated 0 times [  71] [ 0]  / answers: 1 / hits: 5991  / 3 Years ago, mon, october 11, 2021, 4:07:19

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


returns:



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.)?


More From » command-line

 Answers
2

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>



[#26337] Monday, October 11, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dileble

Total Points: 169
Total Questions: 105
Total Answers: 141

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
;