I'm facing an issue with my code where it's only checking the last two variables. I have two pairs: 'a' should match 'b' and 'x' should match 'y'. I want to compare 'a' and 'b' together with 'x' and 'y'. If either pair doesn't match, I want the output to be 'no match'. Here's the snippet I'm using:
```bash
if [[ "$a" == "$b" && "$x" == "$y" ]]; then
echo "match"
else
echo "no match"
fi
```
Can anyone help me figure out why it's not working?
2 Answers
What about trying to rewrite your condition like this?
```bash
if [[ "$a" == "$b" ]] && [[ "$x" == "$y" ]]; then
echo "match"
else
echo "no match"
fi
```
I’ve had success with this format before! Don't forget about spaces too; they can sometimes cause issues.
It looks like your code logic should work fine. You might want to add some echo statements to debug. Try this: `echo "match: '$a' = '$b', '$x' = '$y'"` to see what values are being compared. It might help you track down the issue.
I checked all the variables, and they match perfectly. Just to note, 'b' and 'y' are generated by commands (like cat for 'a' and the date command for 'y'), so maybe that's affecting it.
I tried your suggestion, but even after changing some values, it still shows no match. It feels like it's treating it as an 'or' instead of an 'and'. Any thoughts?
I tried that approach initially but had no luck. Maybe there’s something else going on?