Resolve the directory of the current script.
Section: Script Structure
Get script directory
bash
bash
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)Explanation
Useful for loading sibling files and assets reliably.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Script Structure
Parse short options with getopts
Parse short options using the getopts builtin.
Walk up to repo root
Walk upward until a matching parent directory is found.