[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
automatic unsetting of inherit_errexit with function calls
From: |
crstml |
Subject: |
automatic unsetting of inherit_errexit with function calls |
Date: |
Tue, 22 Aug 2023 17:09:22 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 SeaMonkey/2.53.3 |
Hello all,
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}'"
Here are 2 execution cases:
Case 1:
- line 9 active; line 10 commented
- execution command: bash -e test-subst-and-error.sh
- the statement in the line 12 is NOT reached.
Case 2:
- line 9 commented; line 10 active
- execution command: bash -e test-subst-and-error.sh
- the statement in the line 12 is reached.
Why is there any difference between the case 1 and the case 2?
According to may interpretation of the manual, in a subshell -e
should be automatically unset (unless in posix mode). In reality
I would prefer to not have an automatic unsetting of errexit,
but this is another topic.
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?
Thank you in advance.
Cristian
P.S: As expected, when bash is started without -e the execution
does not stop which is normal.
- automatic unsetting of inherit_errexit with function calls,
crstml <=