I would also assume that if this command was run as root it would not
work, as root's home directory is /root. Same for any other user whose
home directory is not under /home. Perhaps a few-lines script would
first have to grep the login ID from /etc/passwd (read-only, so OK),
parse the line to get the actual home directory and return it.

On 2021-06-17 10:55 a.m., J C Nash wrote:
> 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+unsubscr...@linux-ottawa.org
> To get help send a blank message to linux+h...@linux-ottawa.org
> To visit the archives: https://lists.linux-ottawa.org
>

To unsubscribe send a blank message to linux+unsubscr...@linux-ottawa.org
To get help send a blank message to linux+h...@linux-ottawa.org
To visit the archives: https://lists.linux-ottawa.org

Reply via email to