# Created on savesnippets.com · https://savesnippets.com/IhLlonqlADJ6CJ # Standard form — works for direct invocation and `bash script.sh`. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Symlink-resolving variant (use this if your script may be symlinked): SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)" # Or with realpath (cleaner if you have GNU coreutils): SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" echo "Script lives at: $SCRIPT_DIR" # Source a sibling file relative to this script source "$SCRIPT_DIR/lib/common.sh"