Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
checkrun - a function to get try-catch in bash
function checkrun {
if [ $1 -ne 0 ]; then
echo "$2"
exit 2
fi
}
function test1 {
echo "test1" && \
echo "print 2"
#return 1
}
function test2 {
echo "test2"
}
test1 && test2
checkrun $? 'Something went wrong...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment