When writing bash scripts, you might want to get the directory that contains your script. There are multiple ways to accomplish that. Due to the flexibility of bash, some solutions work in some cases, but not in others.
In this post, I evolve from a naive solution to a robust and consistent solution for this common problem. Spoiler – a “good enough” middle ground that I often use is "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
, as long as I know that symbolic links are out of the game.