The Right Way to Get the Directory of a bash Script

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…. Source: