Get Path of Current Script When Executed Through a Symlink

Try this as a general purpose solution:

DIR="$(cd "$(dirname "$0")" && pwd)"

In the specific case of following symlinks, you could also do this:

DIR="$(dirname "$(readlink -f "$0")")"