2011/11/12 Chris F.A. Johnson <ch...@cfajohnson.com> > On Fri, 11 Nov 2011, Peng Yu wrote: > >> I'm wondering if I already have a string variable, is there a bash >> native to do tilde expansion on it. >> >> var='~/..' >> cd $var#how to change this line? >> > > eval "cd $var" >
I'd avoid eval as that could potentially do more than just expand the tilde, depending on what other characters the var contains. I'd just replace the ~ with $HOME using parameter expansion. cd "${var/#~\//$HOME/}" -- Geir Hauge