help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Check existence but not dereference symlink


From: Peng Yu
Subject: Check existence but not dereference symlink
Date: Fri, 26 Mar 2021 16:17:06 -0500

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]