44

I'm running Ubuntu 11.04, and I'm seeing some odd behaviour when I try to use tab-completion in bash on a path that starts with a variable. If I've got TOP=/scratch, and I try to tab-complete:

cd $TOP/foo

it changes to:

cd \$TOP/foo

I'd prefer it to complete to: cd $TOP/foobar or cd /scratch/foobar but I'd settle for it just not changing the line and requiring me to un-escape the $.

Does anyone know where in bash/readline I should look to fix this?

3
  • 2
    another workaround: use <Esc>+<Ctrl>-E or <Ctrl><Alt>-E to expand the var. [askubuntu.com/questions/41891/… [1]: askubuntu.com/questions/41891/… Commented Apr 28, 2013 at 5:02
  • My workaround is this: sudo yum remove bash-completion. Tab complete still works but just isn't as customizable. Importantly, paths in variables don't expand and remain as variables after hitting tab. Commented Jan 20, 2015 at 6:51
  • I’m running on Centos 8 and I see the same annoying behaviour. It was fine on Centos 6. And this is in 2020. Commented Jul 13, 2020 at 20:55

3 Answers 3

44

Found the bug report, please register (if not already registered) and add yourself to the 'people affected' list, I just did:

https://bugs.launchpad.net/ubuntu/+source/bash/+bug/778627

Workarounds

Try enabling direxpand or cdable_vars:

shopt -s direxpand
# or
shopt -s cdable_vars

Apparently EscTab might be a workaround:

I haven't found a proper solution to this, but there's a workaround. The escaping of environment variables can be disabled by pressing Esc followed by tab.

# cd $SO + [Esc] + [Tab]
# cd $SOME_DIR

Confirm that as a bug! I just confirmed that the same thing works on

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.10
Release:        10.10
Codename:       maverick

I get broken behaviour on (up-to-date) natty:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 11.04
Release:    11.04
Codename:   natty

Although I must add that I do not the slash escaped, but the path (while valid, existing, accessible and readable) is not getting expanded.

Info: https://help.ubuntu.com/community/ReportingBugs

Sign up to request clarification or add additional context in comments.

Comments

15

The bug report refered to in other answers at bugs.launchpad.net gives a new workaround by issuing the command:

shopt -s direxpand

It works for me.

1 Comment

How does this work for you, I don't see any different in behavior with it set or unset? ESC-^E does expand the var in place for me which helps. I'm on Bash 4.2.25
1

I was having a similar problem in cygwin (NT-6.1 2.0.1 2015-04-30) bash (GNU 4.3.33), especially when I would try to tab-expand a path that contained spaces.

I put shopt -s direxpand in my ~/.bashrc. Problem solved.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.