Shell tips: Can a Bash script tell what directory it's stored in?
Question: How do I get the path of the directory in which a Bash script is located FROM that Bash script? Answer: DIR = "$( cd " $ ( dirname "${BASH_SOURCE[0]}" ) " && pwd )" is a useful one-liner which will give you the full directory name of the script no matter where it is being called from. This will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you want to also resolve any links to the script itself, you need a multi-line solution: SOURCE = "${BASH_SOURCE[0]}" while [ - h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink DIR = "$( cd -P " $ ( dirname "$SOURCE" ) " && pwd )" SOURCE = "$(readlink " $SOURCE ")" [[ $SOURCE != /* ]] && SOURCE = "$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative ...