Created
November 17, 2014 17:50
-
-
Save danpoltawski/700a4d8c9571596b01ca to your computer and use it in GitHub Desktop.
error trap
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
| danp@lisa:~$ cat test.sh | |
| #!/bin/bash | |
| set -e | |
| grep 'foo' /file/which/doesnt/exist || echo 'grep failed' | |
| if some-non-existant-command | |
| then | |
| echo 'Its a bug' | |
| else | |
| echo 'report error' | |
| fi | |
| echo 'We get here' | |
| grep 'foo' /file/which/doesnt/exist | |
| echo 'but not here' | |
| danp@lisa:~$ ./test.sh | |
| grep: /file/which/doesnt/exist: No such file or directory | |
| grep failed | |
| ./test.sh: line 7: some-non-existant-command: command not found | |
| report error | |
| We get here | |
| grep: /file/which/doesnt/exist: No such file or directory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment