8

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?

6
  • Slightly unrelated to the question but I find the tldr pages command to be very useful for reading up on other commands in general :)
    – Hoi_A
    Feb 21, 2017 at 13:14
  • @Hoi_A Indeed tldr is a very handy tool with succinct examples. It just happens that some builtin functions were missing from tldr. E.g. hash, fc ,etc. Perhaps will open an issue there Feb 22, 2017 at 17:03
  • I did not know that, I always assumed they had covered all main commands. You could probably just add it to tldr directly instead of an issue since they welcome contributions :)
    – Hoi_A
    Feb 22, 2017 at 17:04
  • 1
    zsh has it own help function called run-help. You will find information on setting up run-help in man zshcontrib.
    – fd0
    Feb 22, 2017 at 18:29
  • 1
    In zsh, use man zshbuiltins. Aug 17, 2017 at 14:58

3 Answers 3

10

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.
4
  • 1
    stupid me, I am on zsh where help is not a builtin Feb 21, 2017 at 7:13
  • you an also use the "man" command: "man fc" will give you the manual pages for the "fc" command Feb 21, 2017 at 16:03
  • 4
    man fc will give you the page for all builtin shell commands (for csh and sh) without any usage details of any of them. Basically, exactly what the OP linked to in the question. Feb 21, 2017 at 16:16
  • 5
    In zsh, use man zshbuiltins. Aug 17, 2017 at 14:57
8

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.

1
  • 1
    Other than some scripting on that man page, is there a way to get run-help work on MacOS?
    – RexYuan
    Jan 4, 2021 at 15:42
0

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.

You must log in to answer this question.

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