TECHNICAL REFERENCE · NOVEMBER 2026
Six completion variables
Input context
COMP_WORDS is an array of parsed words. COMP_CWORD indexes the current word (zero-based).
Output
COMPREPLY is the array of completion candidates supplied by the function.
Other context
COMP_LINE is the full command line; COMP_POINT is the cursor offset in that line; COMP_WORDBREAKS contains word-separator characters.
Minimal example
_speak_complete() {
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "hello goodbye later" -- "$cur") )
}
complete -F _speak_complete speak
Tip
This small example is intended for simple fixed words; for complex quoting and filenames, use the bash-completion helpers or robust array handling.