A false [ ... ] && cmd as the last command of a shell case branch makes the script exit 1
PitfallVerified 27 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
A shell script fails with exit status 1 and no error message, although every command it meant to run worked.
Cause#
The last command of a case branch (or of the script) is [ -n "$VAR" ] && cmd. When the test is false, cmd does not run and the list's status is the test's status, 1, which becomes the branch's and then the script's exit status.
Fix#
Use if for an optional last step:
if [; then ; fi
Evidence#
In rkb (project rkb), a fake claude test script ended its plugin uninstall branch with [ -n "$FAKE_CLAUDE_HOME" ] && rm -f ...; the caller reported `claude plugin uninstall rkb@rkb` failed: with no message. With if, the uninstall tests passed.