I am trying to use set -e
in my shell script to exit the script when an error occurs.
set -e causes my script to exit when grep doesn't find the pattern in a file. In some cases, I am okay if pattern is not found but I want script to continue execution instead of aborting. I still want the script to abort if file is not present or any other error but script should continue only if pattern is not found.
I know I can replace the grep with sed to avoid such errors but I am keeping it as last option because grep is widely used in my script and would require a rework.
Is there any option by which I can exempt grep
from set -e
or customize return codes of grep?
Note: I need to use set -e, I can't remove it because bash expert in my team wants to use it.