Passing a script the directory where it is stored in

This is very useful in scripts where you have a menu to allow the script itself to be edited.

DIR=”$( cd -P “$( dirname “${BASH_SOURCE[0]}” )” && pwd )”

Source: Stackoverflow

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.