bash 4.2 $variable expansion bug

bash-4.2 (default on Ubuntu) has a super annoying bug.

d=/usr/bin
ls $d/ssh-keyg[user presses tab]
ls \$d/ssh-key

In a nutshell, bash “helpfully” adds a backslash to escape the dollar sign because the user must have meant the literal character $. Previous to bash-4.2 it would have expanded the variable, so we would have seen “ls /usr/bin/ssh-keygen” instead. Which is way more useful

A quick search online finds the usual set of incorrect explanations and cargo-cult changes to bash-completion. (A popular fix is to use complete to make it so that the “cd” command works, leaving expansion broken for every other command.)

The actual truth is that this expansion is intended behavior in 4.2. Chet Ramey himself said so. He also recognizes this is awkward and has written a patch to add a new shopt called “direxpand” that will restore the desired, pre-4.2 behavior. Sadly that patch hasn’t made its way into Ubuntu’s Oneiric distribution yet.

One workaround for now is to press ESC C-e before hitting tab; that forces the command line to expand everything first.