From f94dff5f3f0814d068c602d27ef376fbe30a27f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Thu, 18 May 2017 18:31:24 +0200 Subject: [PATCH] handle ENOENT properly in does_pattern_exist_in_file\(\) --- lib/utils.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/utils.sh b/lib/utils.sh index 118cf35..579b961 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -100,11 +100,16 @@ does_pattern_exist_in_file() { local PATTERN=$2 debug "Checking if $PATTERN is present in $FILE" - debug "grep -qE -- '$PATTERN' $FILE" - if $(grep -qE -- "$PATTERN" $FILE); then - FNRET=0 + if [ -r "$FILE" ] ; then + debug "grep -qE -- '$PATTERN' $FILE" + if $(grep -qE -- "$PATTERN" $FILE); then + FNRET=0 + else + FNRET=1 + fi else - FNRET=1 + debug "File $FILE is not readable!" + FNRET=2 fi }