Take the 2-minute tour ×
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

closed as off-topic by Warren Hill, Eric Carvalho, Eliah Kagan, Thomas W., Kevin Bowen Jul 12 '13 at 12:21

  • This question does not appear to be about Ubuntu within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the 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
4  
This question appears to be off-topic because it is about a bug in an old unsupported release. The bug is described here and has been fixed in 12.04 and later –  Warren Hill Jul 11 '13 at 7:38
1  
@WarrenHill This may be off-topic because it's about a bug (and I've voted to close it for that reason). That the bug is in an unsupported release is irrelevant though--we don't close old questions that have answers as off-topic when the affected release's EoL date comes along. Only new/unanswered EoL questions are off-topic. –  Eliah Kagan Jul 11 '13 at 21:41
add comment

4 Answers 4

To get the old behaivior back, use the command

shopt -s direxpand

or include it in your .bashrc

If you use the same .bashrc with different versions of bash, use

if ((BASH_VERSINFO[0] >= 4)) && ((BASH_VERSINFO[1] >= 2))
    then shopt -s direxpand
fi
share|improve this answer
    
That test will fail for bash 5.0 and 5.1. –  Keith Thompson Jan 20 at 23:31
add comment

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
add comment

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
add comment

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
add comment

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