lundi 9 septembre 2019

Arithmetic expression inside [[

I have this code:

fruit=apple
flag=0

[[ $fruit = "apple" && ((flag == 0)) ]]  && echo "1"
[[ $fruit = "apple" && (($flag == 0)) ]] && echo "2"
[[ $fruit = "apple" && ((! flag)) ]]     && echo "3"
[[ $fruit = "apple" && ((! $flag)) ]]    && echo "4"

All of them are expected to echo something. However, only the second statement works properly:

[[ $fruit = "apple" && (($flag == 0)) ]] && echo "2"

Why is this? Won't arithmetic expressions work properly inside [[ ]]?

Aucun commentaire:

Enregistrer un commentaire