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