mardi 2 janvier 2018

bash script: if condition does not work (is never true) [duplicate]

This question already has an answer here:

Like I mentioned in the title the if condition does not work because is never verified and I am sure the output of the tail command contains the substring I'm looking for.

tail="tail /file.txt"
eval $tail
output=$(eval $x)
echo $output

var1="public";

if [[ "$output" =~ "$var1" ]] 
    then 
        echo Contains the string.
    else
        echo Does not contain the string.
fi

I also tried like this but still does not work.

if [[ $output == *"public"* ]]

Aucun commentaire:

Enregistrer un commentaire