LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

compgen

generate completion matches in bash

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 is a Bash builtin that generates possible completion matches for a word. It is primarily used inside programmable completion functions but is also useful interactively for discovering available commands, functions, variables, and other shell entities. When given a word argument, only matches starting with that word are shown.

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
Kai