Skip to content

Instantly share code, notes, and snippets.

@danpoltawski
Created November 17, 2014 17:50
Show Gist options
  • Select an option

  • Save danpoltawski/700a4d8c9571596b01ca to your computer and use it in GitHub Desktop.

Select an option

Save danpoltawski/700a4d8c9571596b01ca to your computer and use it in GitHub Desktop.
error trap
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