[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check existence but not dereference symlink
From: |
Alex fxmbsw7 Ratchev |
Subject: |
Re: Check existence but not dereference symlink |
Date: |
Fri, 26 Mar 2021 22:55:05 +0100 |
and [[ -e doesnt dereference
you specify a not non existing position so it returns true
On Fri, Mar 26, 2021 at 10:20 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> Hi,
>
> ln -s 1.txt a.txt
> [[ -a a.txt ]]; echo $?
> 1
> [[ -e a.txt ]]; echo $?
> 1
>
> [[ -e path ]] and [[ -e path ]] will deference symlink. If the target
> does not exist, it will return an error.
>
> I want to check the existence of a path without dereferencing symlink.
> I come up with this, but it is a little verbose. Is this the best way
> to do so?
>
> [[ -f path || -h path || -d path ]]
>
> --
> Regards,
> Peng
>