Getting a Sourced Bash Script’s Own Path
When you source a script using . script.sh or source script.sh, the $0 variable doesn’t point to the sourced script—it stays as the path of the parent shell or calling script. This creates a problem if you need the sourced script to know its own location. The solution: use ${BASH_SOURCE[0]} The ${BASH_SOURCE[0]} variable holds the…