Skip to content

Instantly share code, notes, and snippets.

@Iristyle

Iristyle/output.txt

Last active Apr 1, 2020
Embed
What would you like to do?
POSIX shell error-handling with set -e
# ./test.sh
140529043738688:error:20087002:BIO routines:BIO_lookup:system lib:../crypto/bio/b_addr.c:694:Name or service not known
connect:errno=2
else branch - ignored error - output: foo
command output:
bar
140510615253056:error:20087002:BIO routines:BIO_lookup:system lib:../crypto/bio/b_addr.c:694:Name or service not known
connect:errno=2
entered loop - ignored error
bar
140520604876864:error:20087002:BIO routines:BIO_lookup:system lib:../crypto/bio/b_addr.c:694:Name or service not known
connect:errno=2
script complete
set -e
err() {
echo "$1"
printf "GET \foo\bar\n\n" | openssl s_client -connect puppet:8140 -ign_eof -quiet
return 1
}
output="none"
if output=$(err "foo") > ./output.txt; then
echo "if branch - ignored error - output: $output"
else
echo "else branch - ignored error - output: $output"
fi
exitloop=false
while ! (err "bar" || $exitloop); do
echo "entered loop - ignored error"
exitloop=true
done
echo "script complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.