Skip to main content
2 of 3
more information to better describe the solution
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k

You could decide that the exit status 77 for instance means exit any level of subshell, and do

set -E
trap '[ "$?" -ne 77 ] || exit 77' ERR

(echo here; (echo there; (exit 12); echo ici; exit 77);
echo not here); echo not here either

set -E in combination with ERR traps is a bit like an improved version of set -e in that it allows you to define your own error handling.

In zsh, ERR traps are inherited automatically, so you don't need set -E, you can also define traps as TRAPERR() functions, and modify them through $functions[TRAPERR], like functions[TRAPERR]="echo was here; $functions[TRAPERR]"

Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k