home | list info | list archive | date index | thread index

expansion of tilde for home directory

While I've found a workaround, I was a bit surprised that a test for existence of
a directory in a bash script did not work.

I tried

DIR="~/Something/"
if [ -d "$DIR" ]; then

and got that the directory did NOT exist when it was clearly there.

Workaround was to use

DIR="/home/$(basename ~)/Something/"

I did a bit of a search, but found no mention of the fact that ~ is not
expanded in the if [  ] construct. Is it, in fact, "well-known" except
to me?

Cheers, JN



To unsubscribe send a blank message to linux+unsubscribe [ at ] linux-ottawa [ dot ] org
To get help send a blank message to linux+help [ at ] linux-ottawa [ dot ] org
To visit the archives: https://lists.linux-ottawa.org