2

Is there an equivalent of -e that works inside bash functions, and returns instead of exiting? Here is an example:

#! /usr/bin/env bash

set -e

function test1() {
  echo A
  ls alskdfal
  echo B
}

test1 || echo C

Right now I get the following output

A
ls: cannot access 'alskdfal': No such file or directory
B

It continues past that error even thought I have set -e. I am looking for a way to get the following, without puttin | return 1 after each line.

A
ls: cannot access 'alskdfal': No such file or directory
C
Alex028502
  • 2,415
  • 12
  • 28
  • See the exercises in [BashFAQ #105](http://mywiki.wooledge.org/BashFAQ/105#Exercises). `set -e`'s behavior is much more contextually-dependent (and prone to variation between shell versions) than you may realize -- relying on it is an easy way to get bugs you wouldn't have if you'd written error-handling code by hand. – Charles Duffy Dec 13 '18 at 18:08

0 Answers0