Set -e
inside the subshell and remove the ||:
:
#!/bin/bash -u
items="1 2"
for item in $items; do
(
set -e
echo one
false
echo two
)
done
Another seemingly working approach is:
#!/bin/bash -eu
items="1 2"
for item in $items; do
(
echo one
false
echo two
) | awk '{print}'
done
I suppose the reason why your approach doesn't work is the following (quoted from man bash
):
The shell does not exit if the command that fails is [...] part of any command executed in a
&&
or||
list except the command following the final&&
or||