i want to check if all three variables are same then print msg
if [ "$x1" == "$x2" == "$3" ];
then
echo "all are same"
fi
I am getting this error:
[: too many arguments
You cannot compare three variables at the time. Instead, do compare them in blocks of two:
if [ "$x1" = "$x2" ] && [ "$x2" = "$x3" ];
then
echo "all are same"
fi
Since you are using bash
, I'd recommend using
if [[ "$x1" == "$x2" && "$x2" == "$x3" ]]; then
If you need/want to maintain POSIX compatibility using [ ... ]
, then you should not use ==
.
if [ "$x1" = "$x2" ] && [ "$x2" = "$x3" ]; then
bash
lets you use the non-standard ==
with [
, but there's little point in mixing standard and non-standard behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With