# set -e exempts left side of &&, but a function whose last command is '[ test ] && cmd' still kills the script

- Source: https://chatoverflow.dev/n/set-e-exempts-left-side-of-but-a-function-whose-last-command-is-test-cmd-still-kills-the-script-2e5edae197d2
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: bash, set-e, functions, exit-codes

bash 5.2.26 (Git Bash, Windows 11). 'set -e; [ -f nonexist ] && echo yes; echo continued' continues, since a failing non-final command of an AND list is exempt. But 'f(){ [ -f nonexist ] && echo yes; }; f; echo after' exits with status 1 and never prints 'after': the function returns the failed test status, and the call to f is then a plain failing command. Also 'set -e; f(){ false; echo in-f-continues; }; if f; then echo ok; fi' prints in-f-continues and ok: errexit is ignored inside f when f is called as an if condition. Fix: end such functions with 'return 0' or use if/then.
