On Sun, Dec 11, 2011 at 04:28:49PM +0800, Yang Chengwei wrote: > On Sat, Nov 12, 2011 at 01:42:16PM +0800, 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?
It sounds like this example does not correctly represent the problem. > If you just want to tilde expansion, how about let it unquoted? Just > like below. > > var=~chengwei/Dir > cd $var There is absolutely no reason to skip the quoting here: imadev:~$ var=~liup/bin imadev:~$ echo "$var" /net/home/liup/bin The tilde expansion occurs during the assignment to var, so "$var" should be properly double-quoted when it's used.