Comment by Joker_vD

4 years ago

I see that there are lots of comments about problems of TAB-completions with filenames with spaces in this comment section and I am frankly puzzled: both Bash and cmd.exe actually TAB-complete those perfectly fine, inserting quoting where it's needed.

And where it isn't needed. If you have a path that contains a variable and a space, bash will happily escape the $, making the path invalid. See the following:

  $ cd $HOME
  $ mkdir my\ dir
  $ ls my[tab]
  $ cd /
  $ ls $HOME/my[tab]
  ls: cannot access '$HOME/my dir/': No such file or directory

That error is because when you press [tab], bash changed the path to \$HOME/my\ dir/ but that isn't obvious from the output and I couldn't find a proper way to include the tab-expanded result in the transcript.

(edit: this is on GNU bash, version 4.3.48(1)-release but I've seen this behaviour for years)

I seem to remember bash losing preferred escaping when TAB-completing, but can't reproduce it now with 5.0.17.

Eg. you'd type `ls -l "Spaced [TAB]` and it would turn it into `ls -l Spaced\ Name`. I remember similar annoyances with other special shell characters (eg. single quotes, dollars, slashes), but that all seems to behave sane now.

  • I didn't even know this was a thing, but can't say I've ever preferred an escape style. I actually use backslashes a fair bit, usually just with spaces. I tend to reserve double quotes for variable or shell expansion, explicitly.

    • It's not so much about a preference, but your cursor would jump about and you'd need to be on the lookout if you wanted to edit the completion (eg. to change the extension).

> inserting quoting where it's needed

You have to remind yourself to do this manually in scripts if you don't want to see lines full of "No such file or directory."

One of the reasons the shell is broken is because the character they use as an argument array member separator is something that regular people use to distinguish between two words, such as in a file name.

  • Well, writing scripts would be much less painful if $VARNAME did not explode into pieces by default. Alas, this ship has sailed long ago.

    • IMHO, it's possible to add a flag to bash, which will turn on this behavior, so problem can be fixed, but it will diverge bash from POSIX sh a lot.