From 4ff123a203dc724e524b256928e2fe60c8125575 Mon Sep 17 00:00:00 2001 From: pvincent Date: Fri, 20 Aug 2021 15:03:30 +0400 Subject: [PATCH] fix: append_or_replace works for '/' chars --- tools/append_or_replace | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/append_or_replace b/tools/append_or_replace index 077c859..5fc5fe6 100755 --- a/tools/append_or_replace +++ b/tools/append_or_replace @@ -1,6 +1,5 @@ #!/bin/bash - usage() { echo "Usage: $(basename "$0") " } @@ -8,17 +7,16 @@ usage() { if [[ $# -ne 3 ]]; then usage exit 2 -fi +fi REGEX=$1 STRING=$2 FILE=$3 -grep -q "$REGEX" $FILE -if [ $? -eq 1 ]; then - echo "$STRING" >> $FILE +if ! grep -q "$REGEX" "$FILE"; then + echo "$STRING" >>$FILE echo appended else - sed -i "s/$REGEX/$STRING/g" $FILE + sed -i "s|$REGEX|$STRING|g" $FILE echo replaced fi