[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: automatic unsetting of inherit_errexit with function calls
From: |
Lawrence Velázquez |
Subject: |
Re: automatic unsetting of inherit_errexit with function calls |
Date: |
Tue, 22 Aug 2023 21:16:29 -0400 |
User-agent: |
Cyrus-JMAP/3.9.0-alpha0-647-g545049cfe6-fm-20230814.001-g545049cf |
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).
--
vq