Seguindo neste post
Eu tenho esse script bash que eu esperaria que terminasse completamente ao clicar no false
e, ainda assim, não termina. Eu reconheço que estou fazendo coisas um pouco diferentes do post vinculado.
#!/usr/bin/env bash
set -Eeuo pipefail
function thing() {
false
echo "thing1|thing2|thing3"
}
IFS='|' read -r one two three <<< "$(thing )"
echo "${one} ${two} ${three}"
echo "done"
Saída:
thing1 thing2 thing3
done
O ideal seria fazer isso no zsh, mas também recebo um comportamento que não desejo:
#!/usr/bin/env zsh
set -Eeuo pipefail
function thing() {
false
echo "thing1|thing2|thing3"
}
IFS='|' read -r one two three <<< "$(thing )"
echo "${one} ${two} ${three}"
echo "done"
saída:
done
Como fazer isso funcionar?
Em geral, você nunca deve confiar em
errexit
( https://mywiki.wooledge.org/BashFAQ/105 ). Para este caso em particular, não acho que você possa usar o herestring, mas você poderia fazer algo como:Explícito é melhor que implícito, e
... || exit 1
é algo lindo de se ver.Você pode fazer
mas verificar se há um erro explicitamente, como William sugere em sua resposta, é melhor.