Linux – bash: variable name not being expanded with Tab completion

bashcommand lineenvironment-variableslinuxshell

On a remote computer with bash version "3.2.51(1)-release" (OS: SUSE Linux Enterprise Server 11.1 (x86_64)), I could not do a usual tab completion with variable name. for example, I'd like to type:

echo $OLDPWD/

then at the end of the slash, I can hit "Tab" and the variable name would be expanded to the old directory name (before the last cd or pushd command). This works in my own laptop (Debian 7, Bash 4.2.37(1)-release). Why in this SLES bash shell it would not work?

Similarly, if I type

echo $OLDP

and then hit "Tab" at the end of the "P" there, bash would complete that to $OLDPWD. This would not happen in SLES 11 bash too.

What control variables (shopt? set?) that affect this behavior?

Best Answer

shopt -s direxpand will make echo $HOME/<tab> expand to echo /home/matt/ in bash 4.2. In bash 4.1 it should be the default.

I find that bash-completion can really mess things up. I always either uninstall bash-completion or run complete -r to make sure that the individual completion rules aren't doing something stupid to the default completions.

If $OLDPWD is actually set then echo $OLDP<tab> should expand to echo $OLDPWD. I don't know what would keep that from happening.