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.

2
  • 1
    That's a version of #2, but using file name to compare instead of inode number. I suspect you've got a few bugs there (e.g., $0 will often just be kitchen, so it won't match). realpath could deal with those, but it has the same limitations as zevzek pointed out in their comment. Commented Sep 22, 2021 at 20:45
  • or maybe IFS=: read -a path <<< "$PATH" and for d in "${path[@]}"; do... to avoid the usual whitespace issues. Which, admittedly, you're not likely to see in PATH, but you only need one joker to use a directory with spaces in the name... Commented Sep 23, 2021 at 11:54