Preventing grep from causing premature termination of "bash -e" script
132
votes
9
answers
100139
views
This script does not output
after
:
#!/bin/bash -e
echo "before"
echo "anything" | grep e # it would if I searched for 'y' instead
echo "after"
exit
I could solve this by removing the -e
option on the shebang line, but I wish to keep it so my script stops if there is an error. I do not consider grep
finding no match as an error. How may I prevent it from exiting so abruptly?
Asked by iago-lito
(2931 rep)
Dec 15, 2016, 04:23 PM
Last activity: Dec 5, 2024, 05:12 PM
Last activity: Dec 5, 2024, 05:12 PM