compgen
TLDR
List all commands
$ compgen -c
List commands starting with prefix$ compgen -c [ls]
List all aliases$ compgen -a
List all shell functions$ compgen -A function
List all builtins$ compgen -b
List all variables$ compgen -v
Complete from word list$ compgen -W '[start stop restart]' -- [sta]
List all users$ compgen -u
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.


