Hacker News new | ask | show | jobs
by renewiltord 2218 days ago
I think I might have a few hundred copies of:

```

# From https://stackoverflow.com/a/246128

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

```

1 comments

I think shell is the most plagiarized code in existence.

So many sysadmins have rudimentary skills and simply copy what works.

I have seen some folks with huge repos of code snippets like that

For sure, and the funny thing is that it can be replaced often by replaced by the simpler and more readable

    DIR=$(dirname $(readlink -f $0))
However OS X doesn't have readlink, so the longer BASH_SOURCE thing makes sense there.

I started using the longer one, and then I gave up on shell scripting on OS X for other reasons, and didn't go back. So yeah there is a lot of random cargo culting.

In Oil I hope to provide an even simpler method that's built in (and it also has readlink builtin to support this)

https://github.com/oilshell/oil/issues/587

I think I actually eventually solved this by installing `coreutils` on OS X and using `realpath`.