Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

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 \>.

share|improve this answer
    
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 7:54
add comment

Luckily there's nothing else ending in ...read so this should work:

help *read
share|improve this answer
    
+1 This is a good solution, but setting Pablo's as accepted since it also works for commands which end with the same string like set. –  l0b0 Feb 26 '13 at 7:53
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.