Issue
I want to store the result of a bash string comparison in a variable, with effect equivalent to:
if [[ $a == $b ]]; then
res=1
else
res=0
fi
I was hoping to be able to write something terser, like:
res2=$('$a'=='$b') #Not valid bash
Is there a way to achieve what I want, without deferring to an if construct?
Solution
I would suggest either:
res=0; [ "$a" == "$b" ] && res=1
or
res=1; [ "$a" == "$b" ] || res=0
Not quite as simple as you were hoping for, but does avoid the if ... else ... fi
.
Answered By - twalberg Answer Checked By - Pedro (WPSolving Volunteer)