Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In bash, environmental variables not tab-expanding correctly

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?

like image 828
Herge Avatar asked Sep 19 '08 16:09

Herge


People also ask

How do I set environment variables in bash?

The easiest way to set environment variables in Bash is to use the “export” keyword followed by the variable name, an equal sign and the value to be assigned to the environment variable.

Are bash environment variables case sensitive?

Bash also supports some basic type declaration using the declare option, and bash variables are case sensitive.

How do I see environment variables in bash?

Under bash shell: To list all the environment variables, use the command " env " (or " printenv "). You could also use " set " to list all the variables, including all local variables.

Does Setenv work in bash?

setenv is similar to the set command, that also sets an environment variable's value. However, unlike set, setenv also "exports" this environment variable to any subshells. In this way, it is the equivalent of the bash command export.


3 Answers

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.

like image 160
kynan Avatar answered Oct 13 '22 01:10

kynan


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.

like image 4
bd808 Avatar answered Oct 13 '22 01:10

bd808


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.

like image 3
Brent Avatar answered Oct 13 '22 01:10

Brent