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.

So, What do options [-abcdefgjksuv] stands for?

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

  • 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. – garethTheRed Aug 20 '14 at 10:35
  • 4
    "man compgen", does not exist. use "man bash" – kevinf Sep 11 '15 at 20:16

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

 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 alias
  • -b means Names of shell builtins
  • -c means Names of all commands
  • -d means Names of directory
  • -e means Names of exported shell variables
  • -f means Names of file and functions
  • -g means Names of groups
  • -j means Names of job
  • -k means Names of Shell reserved words
  • -s means Names of service
  • -u means Names of userAlias names
  • -v means Names of shell variables

You can see complete man page here.

  • @Pandya: See options for complete, it's the same as compgen, except -p and -r. – cuonglm Aug 20 '14 at 10:50
  • I've read it from man bash and suggested edit to complete your post so-that I easily accept. – Pandya Aug 20 '14 at 11:02
  • 1
    Any information on how to use compgen -G? Say my pattern is compgen -G '*.zip' and I have the file "foo.zip". compgen will find foo.zip, but what if the user has already typed 'b'. Now, compgen should find nothing. If I give the command compgen -G '*.zip' "b", compgen still finds foo.zip – Edward Falk Jun 22 '16 at 20:04
  • @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 Rostovtsev Feb 11 '17 at 8:43
  • @IliaRostovtsev: see this one for example github.com/scop/bash-completion/blob/… – cuonglm Feb 11 '17 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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