The root 'problem' is that errexit only exits the subshell, it does
not exit the script. I put that in quotes because under some
circumstances that is a feature.
I want the script to exit when an error is detected without any extra code.
see my other email with the "SOLUTION". Hopefully someone
Michael Potter wrote:
Bash Bunch,
Not surprisingly, bash does not exit the script when an error is detected in
a subshell.
I am hopeful that someone has a solution to this (other than: be careful to
not use subshells).
This seems to work unless I'm missing something...
#!/bin/bash
set
Bash Bunch,
Here is how I 'solved' the problem:
function traperr
{
echo "ERROR: ${BASH_SOURCE[0]} ${LINENO}"
# if BASH_SUBSHELL is 0, then script will exit anyway.
if (( $BASH_SUBSHELL >= 1 ))
then
kill $$
fi
}
I put solved in quotes because I do not really care for this so
Bash Bunch,
Not surprisingly, bash does not exit the script when an error is detected in
a subshell.
I am hopeful that someone has a solution to this (other than: be careful to
not use subshells).
Here is the test run:
---
./subshellnofail.sh
BEGIN
ERROR: ./subshellnofail.sh 10