[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check existence but not dereference symlink
From: |
Andreas Kusalananda Kähäri |
Subject: |
Re: Check existence but not dereference symlink |
Date: |
Sat, 27 Mar 2021 13:19:48 +0100 |
On Fri, Mar 26, 2021 at 10:55:05PM +0100, Alex fxmbsw7 Ratchev wrote:
> and [[ -e doesnt dereference
It does dereference symbolic links:
$ touch file
$ ln -s file link
$ ls -l
total 0
-rw-r--r-- 1 myself wheel 0 Mar 27 13:13 file
lrwxr-xr-x 1 myself wheel 4 Mar 27 13:14 link -> file
$ [[ -e link ]] && echo exists
exists
$ rm file
$ [[ -e link ]] && echo exists
$ [[ -h link ]] && echo is link
is link
> you specify a not non existing position so it returns true
I don't understand what you want to say with this.
Also please consider collecting your replies in longer coherent messages
rather than firing off a stream of consiousness in two line chunks per
message.
Regards,
>
> 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
> >
--
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden
.