I am using an if statement to run a different response for each option selected in a yad GUI zenity fork
.
For some reason the if statement works with some options and not with others!?
NOTE : I'm substituting '^'
for '
in the example
opt=^yad --list --column="Option" --column="Description" \
1 "option 1" \
2 "option 2
<i> subtext </i>" \
| cut -c 1^
echo $opt
if [[ $opt == 1 ]]
then
echo 1
elif [[ $opt == 2 ]]
then
echo 2
else
echo error
option one gives: 1 1
option 2 gives: 2 error
.
The variable is being recorded right as is evident by the echo $opt
output. I know it has something to do with the subtext
, if I erase it the problem goes away, but as to why I have no idea.
Can anyone help me with a fix, or suggest a workaround?
Thanks for all of your help! This problem is really stumping me.
Thanks to abhishek phukan for the answer!
By using ==
the shell wanted to treat the variables as a string, -eq
is normally used for integer operations and works better in this case. Why the subtext effected the answer i don't know.