Interpolate variables in path (bash command line)

1.3k views Asked by At

Please, tell me, what should i do , to interpolate variable name in bash command line while I type it?

i.e. $A = ~/tmp/ in tmp folder I have tmp1 and tmp2 folders.

I type: cd $A<TAB> and nothing happes. if i put additional / and type cd $A/tmp1, it will put additional space at the end cd $A/tmp1<space>.

I want the following behavoir: cd $A<TAB> =====> cd ~/tmp/<without additional space>


Any suggestions?

2

There are 2 answers

3
devnull On BEST ANSWER

You need to say:

shopt -s direxpand

Now saying:

cd $A/TAB

(note the / before TAB) would present directories without adding space.

From the manual:

direxpand
         If  set,  bash replaces directory names with the results
         of word expansion when performing  filename  completion.
         This  changes  the contents of the readline editing buf‐
         fer.  If not set, bash attempts  to  preserve  what  the
         user typed.

Moreover, instead of setting a variable by saying:

A="~/tmp"

or

A=~/tmp

say

A="${HOME}/tmp"
0
Paul Evans On

Firstly, you don't want any spaces on either side of your =. Secondly, I have no problem with bash behaving the above way. Try:

complete -r