mardi 20 août 2019

What does "=~" mean in a logical BASH script [duplicate]

This question already has an answer here:

I was reading this post when I saw the comments about the case statement being better described with [[ t1 =~ "$t2" ]].

What does "=~" mean within a logical and why might it be preferred to a case statement when checking if a variable pattern is contained within a string?

Another example:

studentname=$1
activity=$2
time=$3
ifelse [[ $time > 10 ]]; then
    sentence="today $studentname completed $activity for $time"
else
    sentence="$studentname didn't do homework"
fi

if [[ $sentence == *"$time"* ]]; then
    echo $studentname
fi

Aucun commentaire:

Enregistrer un commentaire