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

Re: expansion of tilde for home directory

  • Subject: Re: expansion of tilde for home directory
  • From: jean-Francois Messier <jf [ at ] messier [ dot ] ca>
  • Date: Thu, 17 Jun 2021 11:35:19 -0400
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+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
>

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