Skip to main content
Post Undeleted by Walf
fixed context and syntax
Source Link
Walf
  • 1.6k
  • 1
  • 16
  • 23

There's a simplerThe actual solution:

#!/bin/bash

function bla() {
    return 1
}

bla || { ( echo '1' ) &&'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.

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.

The actual 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.

Post Deleted by Walf
Source Link
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.