Tilde in path doesn’t expand to home directory

You can do (without quotes during variable assignment):

a=~/Foo
cd "$a"

But in this case the variable $a will not store ~/Foo but the expanded form /home/user/Foo. Or you could use eval:

a="~/Foo"
eval cd "$a"

Leave a Comment