When I start typing a file name that contains an equal sign, autocompletion with [tab] shows a strange behaviour:

ls ./foo[tab]    # autocompletion to "./foo\=bar"         <- ok
ls ./foo=[tab]   # autocompletion to "./foo=foo\=bar/"    <- not ok

Is there something I can put into .bashrc to control this behavior or change some autocomplete scripts in /etc?

bash --version
GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)

Probably not. Or, at least, it will be really complex. The problem here is that foo= is interpreted by bash as an attempt to set the variable foo to something. So, when you hit tab it tries to complete with the names of the files in the current directory. It isn't actually completing foo=, it is starting a whole new glob from nothing. Note that it takes two tabs to complete foo=.

To illustrate, you can see the same behavior even if there are no files starting with foo=:

$ ls
bar  baz

Typing foo= and pressing Tab results in:

$ foo= ## first tab does nothing
$ foo= 
bar          baz  ## both file names are printed. 

I doubt there's going to be any way around this since this is a basic function of the shell and the primary way to define variables.

I can think of two workarounds. Either escape the =:

$ ls foo\=  ## hit tab
$ ls foo\=bar 

Or use quotes:

$ ls 'foo=     ## hit tab
$ ls 'foo=bar' ## yes, the final quote is added by the shell. 

Hitting Tab now will expand the file name correctly.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.