Reputation: 985
num1 =0
num2 =0
I want to print OK if both num1 and num2 are 0 in a single if statement.
Upvotes: 0
Views: 217
Reputation: 25599
Alternatively, you can use case/esac without worrying about different styles of if/else
case "$num1$num2" in
"00" ) echo "ok";;
* ) echo "not ok";;
esac
Upvotes: 0
Reputation: 140297
In POSIX shell you can do:
#!/bin/sh
if [ $num1 -eq 0 -a $num2 -eq 0 ]; then
echo "ok"
fi
If you can use bash
then you can do:
#!/bin/bash
if (( num1 == 0 && num2 == 0)); then
echo "ok"
fi
If you want to save keystrokes and don't mind being a bit cryptic you could also do:
#!/bin/bash
if ! (( num1 | num2 )); then
echo "ok"
fi
Upvotes: 4