13

The OS X Man Pages lists out all builtin functions. But where can I find the documentation of a particular one?

For instance, the command fc, on ubuntu I can get its manual by:

> help fc
fc: fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]
Display or execute commands from the history list.

fc is used to list or edit and re-execute commands from the history list.
FIRST and LAST can be numbers specifying the range, or FIRST can be a
string, which means the most recent command beginning with that
string.
....

Another example is the if expression, on ubuntu:

> help if
if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
Execute commands based on conditional.
...

What am I missing here?

4
  • 1
    zsh has it own help function called run-help. You will find information on setting up run-help in man zshcontrib.
    – fd0
    Commented Feb 22, 2017 at 18:29
  • 1
    In zsh, use man zshbuiltins. Commented Aug 17, 2017 at 14:58
  • See also apple.stackexchange.com/questions/239484/…
    – cachius
    Commented Jun 13, 2023 at 4:39
  • First URL is dead :(.
    – athena
    Commented Aug 25 at 21:30

4 Answers 4

13

As long as you use bash, you do the exact same thing.

So...

$ help if
if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
    The `if COMMANDS' list is executed.  If its exit status is zero, then the
    `then COMMANDS' list is executed.  Otherwise, each `elif COMMANDS' list is
    executed in turn, and if its exit status is zero, the corresponding
    `then COMMANDS' list is executed and the if command completes.  Otherwise,
    the `else COMMANDS' list is executed, if present.  The exit status of the
    entire construct is the exit status of the last command executed, or zero
    if no condition tested true.

Or...

$ help fc
fc: fc [-e ename] [-nlr] [first] [last] or fc -s [pat=rep] [cmd]
    fc is used to list or edit and re-execute commands from the history list.
    FIRST and LAST can be numbers specifying the range, or FIRST can be a
    string, which means the most recent command beginning with that
    string.

       -e ENAME selects which editor to use.  Default is FCEDIT, then EDITOR,
          then vi.

       -l means list lines instead of editing.
       -n means no line numbers listed.
       -r means reverse the order of the lines (making it newest listed first).

    With the `fc -s [pat=rep ...] [command]' format, the command is
    re-executed after the substitution OLD=NEW is performed.

    A useful alias to use with this is r='fc -s', so that typing `r cc'
    runs the last command beginning with `cc' and typing `r' re-executes
    the last command.
1
  • 7
    In zsh, use man zshbuiltins. Commented Aug 17, 2017 at 14:57
15

On macOS Catalina (10.15) and above, use:

man zshbuiltins

That's because zsh is now the default shell on Mac (not bash). As you and @Ricardo noted in the comments above, you can't use help in zsh.

0
2

run-help would work, but is aliased to man. based on man zshcontrib:

To use the run-help function, you need to add lines something like the following to your .zshrc or equivalent startup file:

unalias run-help
autoload run-help

Pressing the escape then H may also work, if you still have default keybinds in place.

1

zshbuiltins as noted above is the correct answer.

In man builtin we can read:

Consult a shell's manual page for details on the operation of its builtin commands.

zshbuiltins is part of man zsh.

This YouTube video is pedagogical and may be usefull for begginers (like me).

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .