4

It seems the Bash built-in help command help does some really strange globbing:

  • help read shows the documentation for read, readarray and readonly.
  • help rea? shows only the documentation for read.
  • help 'read$' doesn't work.
  • help read | sed '/^read[^:]\+/,$d' is just silly.

Is there some more intuitive way to get only the read output?

l0b0
  • 51,350
  • 2
    It seems they have fixed this annoying behaviour with the implicit * at the end if there is an exact match, (at least as of version version 4.3.42). In my version of bash help read shows only the documentation for read, but help read would show the documentation for read, readarray, etc. – Elmar Zander Nov 27 '15 at 08:25

2 Answers2

3

It seems by defaul help foo is actually equivalent to help foo*. But if some special globbing characters are used then the ending "*" is not implicitely added.

So, a possibility would be help [r]ead.

The globbing used is the one used by the shell for file matching; afaik there isn't any equivalent of \< nor \>.

  • It's globbing, just like filename completion, but it is expanded after you enter it, and I don't see anyway to control it (see builtins/help.def, it's a for() loop over all builtins). Since [] trumps *, [r]ead gets my vote. read, time and type are the only problematic complete commands (and the two types of for if you're a pedant). – mr.spuratic Feb 25 '13 at 21:43
  • Accepting since it also works for help [s]et. – l0b0 Feb 26 '13 at 07:54
0

pipe the output of help through a small awk script:

help () {
    builtin help "$1" |
    awk -F: -v command="$1" '
        p && /^[^[:space:]]/ {exit}
        $1 == command {p = 1}
        p
    '
}

Now help read will only give you the help for the read builtin.

glenn jackman
  • 85,964