How may I detect the name of the directory (or better yet the entire path) in which my shell script is run?
This, I believe, is the most portable way:
dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)