lundi 2 août 2021

How to use if elif else in bash

I cannot figure out how to use a simple if/elif/else structure in bash. I cannot believe how something as trivial as that can be so unintuitive and difficult. I've already spent quite a bit of time fiddling around with that. What I want to do is something like that:

aaa="xxx"
if [[ $aaa -eq "bbb" ]]; then
   echo "bbb"
elif [[ $aaa -eq "ccc" ]]; then
   echo "ccc"
else
   echo "something else"
fi

I've tried it with a single [, with two [[, with ((, with == instead of -eq, I'm really not a Linux guy and very confused about the syntax, I've seen all kinds of different syntaxes regardind if conditionals. It always prints bbb, no matter what value aaa has. Can somebody please explain to me how to do this so that it works?

Aucun commentaire:

Enregistrer un commentaire