Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the backslash in bash? [closed]

I exported a variable in ~/.bashrc as follows (followed by source ~/.bashrc)

export w=/home/user/workspace/

When I'm on commandline I try to access sub-directories of $w in following way

user$ vi $w/

After this when I hit the tab key, a mysterious backslash appears

user$ vi \$w/

It disables further tab-completion. Why? May not be vi specific as it occurs even with ls.

Bash version 4.2.24(1)-release (i686-pc-linux-gnu) Running Ubuntu 11.04

Edit Workaround: Hit Esc+Ctrl+E before hitting tab.

like image 354
user13107 Avatar asked Oct 09 '12 04:10

user13107


1 Answers

Bash is a little smart, but not that smart. It's not going to be able to expand out your variable, then tab complete to whatever dir that evaluates to. So it's not the backslash "disabling" tab completion, it's the fact that bash can't find any completion suggestions to make.

Given that completion isn't going to help you if you actually do have environment variables in your path, the only way completion could help you at all is if you meant to type a literal dollar sign. I think bash is just being overzealous in trying to complete to something.

Still, I'd call it a bug, since in your case it not only fails to complete, but also changes the meaning of what you've typed.

like image 191
Mu Mind Avatar answered Nov 15 '22 11:11

Mu Mind