7

I exported a variable in ~/.bashrc as follows (followed by source ~/.bashrc)

export w=/home/user/workspace/

When I'm on commandline I try to access sub-directories of $w in following way

user$ vi $w/

After this when I hit the tab key, a mysterious backslash appears

user$ vi \$w/

It disables further tab-completion. Why? May not be vi specific as it occurs even with ls.

Bash version 4.2.24(1)-release (i686-pc-linux-gnu) Running Ubuntu 11.04

Edit Workaround: Hit Esc+Ctrl+E before hitting tab.

user13107
  • 3,239
  • 4
  • 34
  • 54
  • Probably a bug in the completion package of your distro. It would help if you indicated which Bash version and Linux distro version. – tripleee Oct 09 '12 at 04:35
  • Happens for me on Ubuntu 12.04 w/ bash 4.2.24 and bash-completion 1:1.3-1ubuntu8. – Mu Mind Oct 09 '12 at 04:46
  • @tripleee Added details to the question. – user13107 Oct 09 '12 at 05:25
  • 2
    Found duplicate: http://askubuntu.com/questions/41891/bash-auto-complete-for-environment-variables – user13107 Oct 09 '12 at 05:34
  • not really off-topic, but a duplicate to another SE site (see @user13107's comment) – Rody Oldenhuis Oct 09 '12 at 08:42
  • Given that the question is an almost-duplicate already, can anyone give up-to-date info on the problem, before someone (like me) posts the n-th question? I still experience this problem, so is the bug still there? Or am I the only one having it? – Enlico Oct 26 '18 at 09:46
  • Said [duplicate](https://askubuntu.com/a/318746/929) mentions another "solution": `shopt -s direxpand` – Tobias Kienzler Jan 28 '20 at 14:20

1 Answers1

3

Bash is a little smart, but not that smart. It's not going to be able to expand out your variable, then tab complete to whatever dir that evaluates to. So it's not the backslash "disabling" tab completion, it's the fact that bash can't find any completion suggestions to make.

Given that completion isn't going to help you if you actually do have environment variables in your path, the only way completion could help you at all is if you meant to type a literal dollar sign. I think bash is just being overzealous in trying to complete to something.

Still, I'd call it a bug, since in your case it not only fails to complete, but also changes the meaning of what you've typed.

Mu Mind
  • 10,935
  • 4
  • 38
  • 69