Question

In bash, environmental variables will tab-expand correctly when placed after an echo command, for example:

echo $HOME

But after cd or cat, bash places a \ before the $ sign, like so:

cd \$HOME

If I use a variable as the second argument to a command, it won't expand at all:

cp somefile $HOM

What mysterious option do I have in my .bashrc or .inputrc file that is causing me such distress?

Was it helpful?

Solution

Try complete -r cd to remove the special programmatic completion function that many Linux distributions install for the cd command. The function adds searching a list of of directories specified in the CDPATH variable to tab completions for cd, but at the expense of breaking the default completion behavior.

See http://www.gnu.org/software/bash/manual/bashref.html#Programmable-Completion for more gory details.

OTHER TIPS

What you're describing is a "feature" introduced in bash 4.2. So you don't have any mysterious option causing you distress, but just "intended" behaviour.

I find this very annoying since I preferred it the way it used to be and haven't found any configuration options yet to get the earlier behaviour back. Playing with complete options as suggested by other answers didn't get me anywhere.

For the second instance, you can press ESC before tab to solve it.

I don't know the solution to your problem, but you could look in /etc/bash_completion or the files under /etc/bash_completion.d to determine what commands use autocompletion and how.

help complete

Might also be helpful.

The Bash Reference Manual has more information than you might want on expansion errata.

Section 8.7 looks like it would be the place to start. It give information on the 'complete' function, among other things.

I'm answering 4-year-old question! Fantastic!

This is a bash bug/feature which was unintentionally introduced in v4.2, and was unnoticed for a long period of time. This was pointed out by geirha in this tread. Confirmed as unintended feature here

I came across this problem when running Ubuntu at home. At work I have bash-3.00, so I've spent some time browsing around to see what's going on. I wonder if I can 'downgrade'....

Check the answer for https://superuser.com/questions/434139/urxvt-tab-expand-environment-variables by Dmitry Alexandrov:

This is about direxpand option. $ shopt -s direxpand and $FOO_PATH/ will be expanded by TAB.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top