Bash help builtin command

preview_player
Показать описание
The builtin command `help` of Bash is relatively *help*ful command, especially when you are coding more than just Bash or come back after days of other languages. You might remember the exact syntax, but if you don't, `help` is one issue away to get the correct answer very quick, even faster than searching, and much faster than go through bash(1).

It can look up reserved words, such as `if` or `for`; and other builtin commands, such as `read` or `times`.

Of course, you certainly can't do `if --help`, but you can't ask those builtin commands, either, because there is no `read --help` or `read -h`. Although you do get a quick usage in response to the invalid option, but `help read` is much better with full explanation as you read in bash(1). You just can't certainly what the short options do when you read them.

The following is the full list of issued commands in the recording:

(0:00) help
(0:06) help help
(0:12) help .
(0:15) help :
(0:20) help true
(0:26) help '(('
(0:30) help '[' '{'
(0:35) help function
(0:40) help if
(0:42) help for
(0:45) help while
(0:50) help variables
(1:00) help tim
(1:07) help -d tim
(1:13) help -s tim
(1:15) help -m tim
(1:25) help -d for
(1:27) help -s for

It will search the pattern from the beginning, you can see in (1:07) matches `time` and `times` for "tim"; also you can search for more than one pattern (0:30).

The `help` has three additional options to choose output format:

(1:07) `-d`: output short description for each topic
(1:13) `-s`: output only a short usage synopsis for each topic matching PATTERN
(1:05) `-m`: display usage in pseudo-manpage format

Even I like this help command a lot -- probably after `sleep` time unit suffixes, unfortunately, it does not have everything, e.g. &&. Nonetheless, it's enough for me since the most needed is `help case` like `switch` in C, I think switch statement probably is the one varies a lot among all languages.

It's only two years ago when I accidentally learned the existence of `help` [2], since then, the more questions I read online, the more I feel many people either don't know about bash(1) or just can't even type in search engine, but they can spend five minute writing a forum post to ask a question that's fundamentally an error in syntax.

So, if you are happen to be one don't know about `help`, now you know and hopefully it can help you save some time.

$$$#

* Bash Version 4.2p47 via Gentoo app-shells/bash-4.2_p47
* In Bash
* By Chet Ramey (maintainer)
* GPLv3

Рекомендации по теме