by @CodingExample

How to Get the source directory of a Bash script within the script itself

Home » bash » How to Get the source directory of a Bash script within the script itself

This example will help you to get the full path of an directory using bash script within the script itself.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

Note: The above code, will give you the full directory name, it’s doesn’t matter where you called from.