Last active
December 29, 2015 03:29
-
-
Save gsf/7607995 to your computer and use it in GitHub Desktop.
sh/bash try/catch on error message grep
This file contains hidden or 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
| #!/bin/sh | |
| # Attempt command, printing all output to stdout, catching errors | |
| # based on a regex, erroring out on all other errors | |
| if output=`some-command 2>&1` | |
| then | |
| echo "$output" | |
| else | |
| if echo "$output" | grep 'regex string' | |
| then | |
| something --other --than bailing | |
| else | |
| echo "$output" | |
| exit 1 | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment