How To Apply Error Handling To Sub Shells

40 views Asked by At

script1

#!/bin/sh
set -e

VALUE="`exit 1`"
echo "$VALUE" ok

script2

#!/bin/sh
set -e

echo "`exit 1`" && echo ok

Looks like pretty the same logic

Still the first script fails

./script1; echo $?

prints

1

while the second one doesn't

./script2; echo $?

prints

ok
0

So what is the difference here?

Is it matter of nested sub shell?

How to make set -e to affect all the nested down sub shells?

Or how to make the second script to fail on substitution invocation error with no computation flow even turned to echo ok at all?

Thank you

0

There are 0 answers