Get current directory absolute path from a bash script
![Get current directory absolute path from a bash script](/content/images/size/w2000/2021/01/brett-jordan-7vxlppVfh8M-unsplash.jpg)
To get the absolute dir of the executing script
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)
For sh
:
DIR=$(cd "$(dirname "$(readlink -f "$0")")" >/dev/null 2>&1 && pwd)
![Buy Me A Coffee](https://cdn.buymeacoffee.com/buttons/v2/default-red.png)
To get the absolute dir of the executing script
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)
For sh
:
DIR=$(cd "$(dirname "$(readlink -f "$0")")" >/dev/null 2>&1 && pwd)