66

From help compgen:

$ help compgen
compgen: compgen [-abcdefgjksuv] [-o option]  [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]
    Display possible completions depending on the options.
    
    Intended to be used from within a shell function generating possible
    completions.  If the optional WORD argument is supplied, matches against
    WORD are generated.
    
    Exit Status:
    Returns success unless an invalid option is supplied or an error occurs.

What do options [-abcdefgjksuv] stand for?

In other words, I want to know how to use all options.

3
  • Have you read the man page? man compgen. The man page is for the shell builtins, so you'll have to scroll down to compgen. Aug 20, 2014 at 10:35
  • 17
    "man compgen", does not exist. use "man bash"
    – Kevin
    Sep 11, 2015 at 20:16
  • You can try help compgen.
    – Darkov
    Mar 24, 2020 at 14:00

2 Answers 2

68

Options for compgen command are the same as complete, except -p and -r. From compgen man page:

compgen
 compgen [option] [word]
 Generate possible completion matches for word according to the options, which 
 may be any option accepted by the complete builtin with the exception of -p 
 and -r, and write the matches to the standard output

For options [abcdefgjksuv]:

  • -a means names of aliases
  • -b means names of shell builtins
  • -c means names of all commands
  • -d means names of directories
  • -e means names of exported shell variables
  • -f means names of files
  • -g means names of groups
  • -j means names of jobs
  • -k means names of shell reserved words
  • -s means names of services
  • -u means names of user names
  • -v means names of shell variables

You can see the complete man page here.

3
  • @cuonglm How to list functions that are provided by the service command? For example, using service networking and hitting tab will return force-reload reload restart start stop. Do you know how to get those using compgen?
    – Ilia Ross
    Feb 11, 2017 at 8:43
  • @IliaRostovtsev: see this one for example github.com/scop/bash-completion/blob/…
    – cuonglm
    Feb 11, 2017 at 9:05
  • I looked all over the man bash and couldn't find this info. Turned out it's under the complete command's -A action section. But the man format is hard to read. This answer's format is much better!
    – wisbucky
    Aug 29, 2019 at 0:29
9

At O'Reilly there is a book (bash Quick Reference by Arnold Robbins) that also has the hint form compgen options being described at complete. Going for the complete documentation gives a few other options than listed above. They might not be related to a current versions, BUT there are options no longer or not described in the current version docs.

As of now I have seen on the web these upper case options being used for invocation of compgen or mentioned in complete docs!

compgen [option] [word]
complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G globpat] [-W wordlist]
      [-P prefix] [-S suffix] [-X filterpat] [-F function]
      [-C command] name [name ...]
      complete -pr [name ...]
  • -A action = The action may be one of the following to generate a list of possible completions: (see links)
  • -C command = Run command in a subshell and use its output as the list of completions.
  • -F function = Run shell function in the current shell. Upon its return, retrieve the list of completions from the COMPREPLY array.
  • -G globpat = The filename expansion pattern globpat is expanded to generate the possible completions.
  • -P prefix = prefix is added at the beginning of each possible completion after all other options have been applied.
  • -S suffix = suffix is appended to each possible completion after all other options have been applied.
  • -W wordlist = The wordlist is split using the characters in the IFS special variable as delimiters, and each resultant word is expanded. The possible completions are the members of the resultant list which match the word being completed.
  • -X filterpat = filterpat is a pattern as used for filename expansion. It is applied to the list of possible completions generated by the preceding options and arguments, and each completion matching filterpat is removed from the list. A leading ‘!’ in filterpat negates the pattern; in this case, any completion not matching filterpat is removed.

A rather exhaustive looking version of the documentation can be found in Programmable Completion Builtins.

As both commands are built in command, the official documentation is on your local man page for bash. Use the search option for locating the relevant parts in it. Sorry, but the layout looks somewhat broken (usability reduced in the generated layout) in either view variant, even on the internet services.

You must log in to answer this question.

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