How to get the script’s own path in sourced Bash script?
Posted on In QAIn normal Bash script, $0
is the path to the script. However, when a script is sourced, such as
. a.sh
a.sh’s $0
does not give a.sh
. How to get the a.sh inside a.sh?
Short answer: use ${BASH_SOURCE[0]}
.
You can check this post for details and explanations: How to Get Bash Script’s Own Path.