${BASH_SOURCE[0]}

Gives the path of the current shell file even if that file is was sourced.

${BASH_SOURCE[0]}

Example:

# This file was sourced into environment
# /Users/nkondrat/vintrin-env/sh/modules/tmp2.sh
foo2() {
  echo ${BASH_SOURCE[0]}
}
export -f foo2

Output:

❯foo2
/Users/nkondrat/vintrin-env/sh/modules/tmp2.sh