vendredi 26 octobre 2018

BASH Pattern in IF-Then_Else

I have a Regex that I got to work in a sed search/replace line, but I can't get the Regex to work in an If-Then-Else. This is my sed line:

YELLOW="\033[1;33m"
OUTPUT[0]="$YELLOW ==================================+==================================="
cLEN=${OUTPUT[0]}
cLEN="$(echo $cLEN | sed 's/\\[[:digit:]]\+\[[[:digit:]];[[:digit:]]\+m//g')"

However now I am trying to make an if condition and I can't get the syntax right. I need it to evaluate from the beginning of the line $cLEN

if [[ $cLEN  =~ '^\\[[:digit:]]\+\[[[:digit:]];[[:digit:]]\+m\s' ]]; then
        echo true
    else
        echo error
        exit 1
fi

Aucun commentaire:

Enregistrer un commentaire