Properly handling spaces and quotes in bash completion
What is the correct/best way of handling spaces and quotes in bash completion? Here’s a simple example. I have a command called words (e.g., a dictionary lookup program) that takes various words as arguments. The supported ‘words’ may actually contain spaces, and are defined in a file called words.dat : foo bar one bar two Here’s my first suggested solution: _find_words() { search="$cur" grep -- "^$search" words.dat } _words_complete() { local IFS=$'\n' COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" COMPREPLY=( $( compgen -W "$(_find_words)" -- "$cur" ) ) } complete -F _words_complete words