On Thu, 17 Jun 2021 11:35:19 -0400
jean-Francois Messier wrote:
> I would also assume that if this command was run as root it would not
> work, as root's home directory is /root.
DIR="$(echo ~)/Something/" would "fix" that, but...
... this is why you should not use shell programming for anythin
On Thu 2021-06-17 14:26:01 -0400, Alex Pilon wrote:
> On Thu 2021-06-17 13:43:43 -0400, Ian! D. Allen wrote:
> > As others have said, quoting (even double quoting) hides tilde expansion.
> > Just make sure the tilde isn't inside quotes and it works fine:
> >
> > DIR=~/"Something"
>
> Strictly s
On Thu 2021-06-17 13:43:43 -0400, Ian! D. Allen wrote:
> As others have said, quoting (even double quoting) hides tilde expansion.
> Just make sure the tilde isn't inside quotes and it works fine:
>
> DIR=~/"Something"
Strictly speaking per spec this won't work. Tilde expansion happens
before
> DIR="/home/$(basename ~)/Something/"
As others have pointed out, it's the unquoted tilde in the command
substitution that is expanding above. You could have used this (but
don't):
DIR="$(echo ~)/Something/"
As others have said, quoting (even double quoting) hides tilde expansion.
Just mak
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
On 2021-06-17 10:55 a.m., J C Nash wrote:
DIR="~/Something/"
if [ -d "$DIR" ]; then
DIR=~/Something/
if [ -d "$DIR" ]; then
or
DIR=~/"Something with spaces/"
if [ -d "$DIR" ]; then
On Thu 2021-06-17 10:55:27 -0400, 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.
This is POSIX shell in general.
> I tried
>
> DIR="~/Something/"
Just DIR="$HOME/Something" unless you need to ref
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 ~)/Som