variable

COMP_CWORD

Index of word being completed. The example supplies the index directly.

Formal Syntax & Structure

bash syntaxbash
${COMP_WORDS[COMP_CWORD]}

Return Value

word index

Index of word being completed. The example supplies the index directly.

Working Example

Example Snippetbash
_bm_complete() {    local word candidate    word=${COMP_WORDS[COMP_CWORD]}    COMPREPLY=()    for candidate in start stop status; do        [[ $candidate == "$word"* ]] && COMPREPLY+=("$candidate")    done    return 0}complete -F _bm_complete bmtoolCOMP_WORDS=(bmtool sta)COMP_CWORD=1_bm_completeprintf '%s\n' "${COMPREPLY[@]}"
Bash Reference