Bash tab expansion quotes variables and makes it disfunctional this way


In a terminal with bash running (4.4.23(1)-release) I write:

echo $HOME/.co

and then I press tab and expect to get names proposed which begin with “.co” e.g. “.config”

But it changes to

echo \$HOME/.co

In this state no further expansion is possible because the meaning of the variable has changed.

Other example:

echo $HOME/.con<tab>

It expands to

echo \$HOME/.config/

Because obviously the “.config” can be expanded unambiguously. But no further usage of the expansion in deeper directorys is possible because the variable “$HOME” got already quoted.

Furthermore: When I try to use the tab expansion for changing directories which begin with a variable, I have no expansion at all.

cd $HOME/.conf<tab>

Makes nothing.

How can I fix this?

1 Like

This is interesting. With nixpkgs.bashInteractive on my macOS machine, echo $HOME/.co<tab> works as expected. With the same thing on my NixOS machine, it behaves as you describe. Both are the same version of Bash, which makes me wonder if there’s some sort of Bash configuration on NixOS that’s causing this. I don’t know what kind of configuration could affect pathname completion though.

EDIT: This definitely appears to be the case. nix run nixpkgs.bashInteractive -c bash --norc on NixOS doesn’t exhibit the bug.

1 Like