Skip to main content
1 of 2
Walf
  • 1.6k
  • 1
  • 16
  • 23

There's a simpler solution:

#!/bin/bash

function bla() {
    return 1
}

bla || { ( echo '1' ) && exit 1; }

echo '2'

The error grouping will only execute if bla returns an error status, and exit is not in a subshell so the whole script stops.

Walf
  • 1.6k
  • 1
  • 16
  • 23