In 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.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *