help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: automatic unsetting of inherit_errexit with function calls


From: crstml
Subject: Re: automatic unsetting of inherit_errexit with function calls
Date: Wed, 23 Aug 2023 10:54:13 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 SeaMonkey/2.53.3

Thank you Lawrence for your reply.

In fact I've realized that -e is disabled also in the line 9 immediately
after I've sent the email.

Cristian

Lawrence Velázquez wrote:
On Tue, Aug 22, 2023, at 11:09 AM, crstml@libero.it wrote:
Let's assume the following script named test-subst-and-error.sh:

   1  func()
   2  {
   3      echo "entering func"
   4      : $-
   5      bash -c "echo XXXXXXXX; exit 8"
   6      echo "exiting func"
   7  }
   8
   9   OUTPUT=$(cat non-existing-file.txt)
10   # OUTPUT=$(func)
11
12   echo "OUTPUT: '${OUTPUT}'"

[...]

My only question is: why in the case 1 when external program
is called errexit is not not automatically disabled but it is
disabled when a function is called?
set -e is disabled within both command substitutions.  The difference
is that the exit status of the assignment on line 9 is nonzero,
causing early exit, while that of the assignment on line 10 is zero
(unless the "echo" command on line 6 fails for some reason).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]