Skip to content

Instantly share code, notes, and snippets.

@pirafrank
Created October 18, 2021 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirafrank/7ddbce8c4d92e4018a7e065a206c35d8 to your computer and use it in GitHub Desktop.
Save pirafrank/7ddbce8c4d92e4018a7e065a206c35d8 to your computer and use it in GitHub Desktop.
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