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 regarding 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?
if
structure itself looks fine. The problem is more the[[ ... ]]
construct, which is not related to theif
. Have a look at the bash man page. The section Compound Commands explains both(( ... ))
and[[ .... ]]
. – Pelisse