Reputation: 21
I am having a problem with my if statement, for some reason it will not run. here is the code:
if (( $digit1 -ne $digit2 )); then
echo "test"
fi
I get this error message: line 32: ((: 1 -ne 2 : syntax error in expression (error token is "2 ")
** I have digit set to 2
Upvotes: 0
Views: 166
Reputation: 11469
As @devnull said and adding to that, use :
if [ $digi1 -ne $digi2 ]; then
echo "Unequal numbers"
fi
Upvotes: 1
Reputation: 123458
You are using the form:
((expression))
which evaluates the expression according to the rules of Arithmetic Evalution.
You have two options. Either fix the operator, i.e. use !=
:
if (( d1 != d2 )); then
or use test
:
if [ $d1 -ne $d2 ]; then
If you're using the arithmetic context:
!, ~ logical and bitwise negation
Quoting from help test
:
arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
-lt, -le, -gt, or -ge.
Upvotes: 1