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 will point out a more graceful solution. -- potter On Feb 1, 2008 1:56 PM, Linda Walsh <[EMAIL PROTECTED]> wrote: > > > 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 -o errexit -o noclobber -o nounset -o pipefail > > function traperr > { > echo "TRAPERROR: ${BASH_SOURCE[0]} ${LINENO}" > exit 1 # does not seem to affect the program. > # return 1 # does not seem to affect the program. > } > > set -o errtrace > trap traperr ERR > > echo -n "Test one: " > pipesave=$(set +o |grep pipefail) > set +o pipefail > cat /etc/passwd |while read aLine; do > # note: ending following 'test=' line with a "|true" will > # stop failure from occurring or being detected, if this is > # what you want..., if not, then set -o pipefile and it > # will 'fail' if any are false. > test=$(true | false | true |false) > done > test "$?" != 0 && exit 47 > $pipesave # set pipesave back to original value > > echo -n "ONE Ok; Test two: " > > while read aLine; do > > test=$(true | false | true |false); > done </etc/passwd > > echo "TWO" > > test=$(true | false | true |false); > > echo "END" > > exit 0 >