Hi All,
I came across a bit of code that seems to work, even though I didn't expect it to (now that's wierd!)
#!/bin/sh
set -x
nn=15
if [ nn -eq 15 ]
then
echo "is true"
fi
The above code ends up comparing the string "nn" to number 15, but still evaluates to true. Here's the output when i run it :
+ nn=15
+ [ nn -eq 15 ]
+ echo is true
is true
while with [ "$nn" -eq 15 ], I get:
+ nn=15
+ [ 15 -eq 15 ]
+ echo is true
is true
which is what I expect.
By the way, if you assign nn=25 and run test nn -eq 15, it evaluates to false.
Any Ideas how the integer comparison is working without dereferencing the variable?