Why does Bash escape colon when autocompleting a filename?

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 a

I press Tab, and the result is

ls a\:b

But 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?

2

1 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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like