variable

COMP_KEY

The key code (or last key in a key sequence) that initiated completion. It is distinct from COMP_TYPE. In the default Tab fixture it is 9; custom bindings may differ. This fixture records the value inside the completion callback; it is not an ordinary persistent variable. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Use interactive Bash with default key bindings; expected visible result: BM_VALUE=9.

Formal Syntax & Structure

bash syntaxbash
COMP_KEY

Return Value

shell variable

Expansion yields the current value in its applicable context, not a separate command exit status.

Working Example

Example Snippetbash
# In fresh interactive Bash, enter:bm_demo() { :; }_bm_complete() { printf "\nBM_VALUE=%s\n" "$COMP_KEY"; COMPREPLY=(alpha); }complete -F _bm_complete bm_demo# Type bm_demo al then press Tab, then Enter.
Bash Reference