On 10/6/13 8:37 PM, Carlos Pita wrote: > I'm not completely sure whether this is a bug or not but it seems > not possible to immediately exit a shell when an error happens at 2+ > levels of subshell nesting. Specifically, there is a command at the > top-level shell waiting for the results of a command substitution. > This second command in the first subshell is in turn waiting for the > results of another command substitution. This innermost command fails > but the awaiting commands still finish their execution as if the error > never happened. I've tested this with set -e, set -E, an ERR trap, > explicit exits at each subshell, but to no avail. Below is an example > to reproduce it. > > Repeat-By: > > trap 'exit 1' ERR > > set -e -E > > function xxx { > echo xxx1 > exit 1 > echo xxx2 > } > > function yyy { > echo $(xxx) yyy > } > > yyy > > # => xxx1 yyy > # I wouldn't expect the echo to print any output or execute at all.
$(xxx) is a word expansion, not a command. Bash will only pay attention to the exit status of command substitution in one case (x=$(foo)). This command substitution doesn't contribute to any other command's exit status, especially `echo', and `set -e' doesn't cause the shell to pay attention to it. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/