Em bash
, sabe-se que set -e
ele é ignorado em substituições de comando (a menos que inherit_errexit
esteja habilitado).
Entretanto, quando false
command é executado em substituição de comando, set -e
NÃO é ignorado. Por quê?
Código:
set -e
shopt | grep inherit_errexit
echo hello
a=$(false)
echo world
Esperado:
inherit_errexit off
hello
world
Real:
inherit_errexit off
hello
shell returned 1
É ignorado no subshell. Não é ignorado fora dele.
O status de saída de toda a atribuição
a=$(false)
não é zero, então o shell sai.