When I press Tab in Bash so that it autocompletes a filename that contains a colon, the result of autocompletion escapes the colon. E.g. starting with the following (without executing the last line),
touch a:b
ls aI press Tab, and the result is
ls a\:bBut it doesn't seem to affect anything when I just issue ls a:b. The result is the same as for ls a\:b.
So why does Bash escape the colon? Does it have special meaning in some cases?
21 Answer
The colon is one of the characters inCOMP_WORDBREAKS:
COMP_WORDBREAKS
The set of characters that the Readline library treats as word separators when performing word completion. If COMP_WORDBREAKS is unset, it loses its special properties, even if it is subsequently reset.
As explained inCompletion Items Starting With Colon Character:
The colon breaks words for the completion system (look at the description of the COMP_WORDBREAKS shell variable), so when you type
progname :[TAB]the completion system gets an empty word to complete. If all of the possible completions have `:' as the longest common prefix, then the completion system will insert the colon into the line.
Removing the colon from the COMP_WORDBREAKS environment variable will solve the problem.
See for exampleBash completion for Maven escapes colon.