Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The bash autocomplete feature does not seem to work with environment variables in 11.04. The current behavior is indicated below

export SCRIPT=/home/user/script
cd $SCRIPT/<tab>

results in a \ being added before $SCRIPT i.e. the prompt becomes

cd \$SCRIPT/

Same thing happens if cd is substituted with ls or any other command

Also, if there is an executable file in the path contained in $SCRIPT and I want to run that

$SCRIPT/<tab>

Bash does not show the options inside the folder (regardless of whether there is a single file or multiple files/directories inside the path contained in the environment variables).

In other words, autocomplete does not work with environment variables.

share|improve this question
2  
Here's the bug in launchpad. – pydave May 10 '11 at 23:26
I think it does not have to do with the bash version (4.1 or 4.2). I've just installed bash-4.1 from sources and used it instead of the 4.2.24 (Ubuntu 12.04's version; installed from sources so i don't have to 'hold back' the package at each sys upgrade) and the behaviour is exactly the same. Very, very annoying... – user80307 Jul 30 '12 at 19:41

3 Answers

This bug was introduced in bash 4.2. There's a lengthy thread about it here:

http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00274.html

In short, Chet Ramey, the developer of bash, isn't sure how to go about fixing it yet.

share|improve this answer
Is there a way to revert to bash 4.1 ? – nilchat May 12 '11 at 4:37
A fix is on the way: Chet added a "direxpand" shopt to restore the old behavior. It's not in Oneiric yet. – Nelson Jan 29 '12 at 0:02
2  
It's surprising to me that so few people have complained about this. It's a big change from the way bash has worked for a number of years. – Scott Wilson Feb 12 '12 at 18:00

The workaround suggested in http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00274.html is:

  1. use <Tab>to auto-complete your environment variable s.t. you command line says cd $MYVAR
  2. hit <Esc>+<Ctrl>-E to expand the current command line i.e. substitute $MYVAR by its value, the path
  3. add a / and then enjoy <Tab> auto-completion as usual

This assumes you are in emacs mode (set -o emacs) and have bash_completion set up sensibly for cd (e.g. complete -o nospace -F _cd cd).

Unfortunately this doesn't work in vi mode (set -o vi) because command line expansion is not available then.

share|improve this answer

After typing the shell variable

cd $SCRIPT/

type Cntrl-Alt-E. This expands the variable

cd /home/user/script/

This does work with EDITOR=vi in Fedora 16.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.