Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • the first example does not work when the link points to a relative path... Commented Nov 4, 2019 at 12:20
  • 1
    @inemanja Sure it does. But as I state, this is a text comparison. It treats different paths to the same target as different. If you want to test whether the target of a symbolic link is a particular file, rather than a particular path, use one of the methods I describe below. Commented Nov 4, 2019 at 12:46
  • It's not safe to treat file location as strings for that exact reason - the first example compares strings hence it shows that "/dir/file.txt" and "/dir/../dir/../dir/file.txt" are different files, and they are not. The second example is much more precise. Commented Jul 9, 2020 at 15:42
  • How about wrapping the path in $(realpath "../dir/../otherdir/file.ext") ? Commented Dec 10, 2021 at 12:21
  • @MogensTrasherDK How about that? I don't understand what you're asking. Commented Dec 10, 2021 at 19:53