cd-without-exit
What it does
Section titled “What it does”Reports cd, pushd or popd whose failure is not handled, as in cd dir || exit. It is not reported under set -e, for cd .. or cd /, or for popd -n.
Why it matters
Section titled “Why it matters”If the directory is missing the script goes on in the old one, and the commands that follow (a rm -rf *, a build, a copy) run in the wrong place.
To fix, write cd dir || exit 1, or use set -e.
Example
Section titled “Example”cd buildcd .. && makecd /cd build || exitcd build && makemake && cd buildif cd build; then make; fiwhile cd build; do break; donecd build | catpushd buildpopd -npopdif cd build | cat; then :; fi{ cd build}f() { cd build; }Configuration
Section titled “Configuration”shell: lint: rules: cd-without-exit: warn # off, warn (default), errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line cd-without-exit in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| shellcheck | SC2164 |
full |