Skip to content

Instantly share code, notes, and snippets.

@handakumbura
Last active April 26, 2017 04:57
Show Gist options
  • Save handakumbura/8d424dd4023d67de8a7a77d859fd6720 to your computer and use it in GitHub Desktop.
Save handakumbura/8d424dd4023d67de8a7a77d859fd6720 to your computer and use it in GitHub Desktop.
Error handling with status codes in BASH
#do something if error code denotes a failure
if [ $? -gt 0 ]; then
echo "something went wrong!"
fi
#status checking in command pipe
cat textfile.txt | ( [[ $? == 0 ]] && grep "cat" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment