bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: invoke tilde expansion on quoted string


From: Geir Hauge
Subject: Re: invoke tilde expansion on quoted string
Date: Sat, 12 Nov 2011 15:53:40 +0100

2011/11/12 Chris F.A. Johnson <chris@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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]