1

Normally, one can hit the tab key after entering the first few characters of a filename and get the complete filename (or suggestions in case there are many with the same beginning characters).

However for filenames with peculiar characters, this doesn't seem to work. Specifically, I'm in the ~/.vim/view dir - which contains files with details like fold locations (line numbers) for all files opened with vim. These are the files that vim uses to restore the same "view" with the proper folds, etc. when one reopens a previously used file. Now (at least on my box) these very useful files seem to have the most curious filenames, e.g. ~=+temp=+test.sh=, or =+temp=+test.sh= These files have info on the last "view" of the ~/temp/test.sh and the /temp/test.sh files respectively.

When I go in this dir, and do something like a ls -l ~=+tem and then hit tab, I'd normally expect it to autocomplete to ~=+temp=+test.sh=

But that doesn't happen. Why? And how (if at all) can I make it happen?

I'm using Bash on FreeBSD. For the record, I've tried this on zsh, csh, tcsh and sh (same OS). I've not added any question tags for specific shells, but do feel free to do so if you think it should be done.

  • 2
    ~ is a special character, it expands to ${HOME}. ls \~=+tem<TAB> or ls ./~=+tem<TAB> should work. – tastytea Mar 24 at 7:21
  • Thank you! Silly of me not to have thought of it. Using backslash to escape the special chars does the trick. Although in my particular case, it is the '=' sign that also has to be escaped. – Yogesch Mar 24 at 7:48
  • 2
    Possible duplicate of What characters need to be escaped in files without quotes? – tastytea Mar 24 at 8:09
  • @tastytea, yes, it seems that way, but oddly enough the answer to that question doesn't cover this case. The answer there mentions having to escape '=' only in zsh, but I seem to need to do that even in bash. – Yogesch Mar 24 at 9:32
  • I think that's supposed to mean = has to be escaped, but in zsh only if it is at the beginning of a file name. – tastytea Mar 24 at 9:39
2

It seems to me that Bash ignores the = and the part before it when completing a filename, probably to support GNU style long options like --some-file=<filename>.

For example, if the files foofoo and foobar exist, typing echo asdf=f<tab>, will autocomplete the prefix foo, and list the two filenames.

With a file called asdf=xyz, echo asdf=a<tab> will happily autocomplete that in the part after the =, giving echo asdf=asdf\=xyz.

So yes, you need to escape the = in Bash when autocompleting filenames. It's not an issue for the resulting command, however, it has no special meaning to the shell in that sense.

On the other hand, the tilde in your file names probably isn't a problem. Unless you have a user called =+temp=+test.sh= it should be left as-is.

  • Thanks for clarifying that escaping the '=' is necessary only for autocomplete. Because when I type out the filename as such, there's no need to escape it. – Yogesch Mar 26 at 5:09

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.