Created
October 18, 2021 13:08
-
-
Save pirafrank/7ddbce8c4d92e4018a7e065a206c35d8 to your computer and use it in GitHub Desktop.
checkrun - a function to get try-catch in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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