LinuxCommandLibrary

compgen

TLDR

List all commands

$ compgen -c
copy
List commands starting with prefix
$ compgen -c [ls]
copy
List all aliases
$ compgen -a
copy
List all shell functions
$ compgen -A function
copy
List all builtins
$ compgen -b
copy
List all variables
$ compgen -v
copy
Complete from word list
$ compgen -W '[start stop restart]' -- [sta]
copy
List all users
$ compgen -u
copy

SYNOPSIS

compgen [options] [word]

DESCRIPTION

compgen generates completion matches for word. Bash builtin used for programmable completion. Outputs words matching specified criteria to stdout.

PARAMETERS

-a

Aliases
-b
Builtins
-c
Commands
-d
Directories
-e
Exported variables
-f
Files
-g
Groups
-j
Jobs
-k
Keywords
-s
Services
-u
Users
-v
Variables
-A action
Completion action type
-W wordlist
Complete from word list
-G pattern
Glob pattern for filenames
-P prefix
Add prefix to completions
-S suffix
Add suffix to completions
-X pattern
Filter out matching completions

ACTIONS (-A)

alias, arrayvar, binding, builtin, command, directory, disabled, enabled, export, file, function, group, hostname, job, keyword, running, service, setopt, signal, stopped, user, variable

CAVEATS

Bash builtin only, not available in other shells. Returns true unless invalid option or no matches. Used in completion scripts with complete builtin.

SEE ALSO

complete(1), bash(1)

Copied to clipboard