this line might return null
echo "SOURCE: ${BASH_SOURCE%/*}"
so you could do
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "$DIR"
instead