If I have a variable, say xvar, which can take both string and integer value and I want to perform an operation in following 2 conditions:
1. Either xvar is null
2. xvar equals 2
[ -z "$xvar" ] || [ $xvar -eq 2 ] && <some-code>
Doesn't seem to work if xvar takes string values
I know that since I have no restriction on xvar, I can get away with string comparison in second test too, ie
[ -z "$xvar" ] || [ "$xvar" = "2" ] && <some-code>
But, 'Sams teach yourself shell script in 24 hrs' says that [ expr1 -eq expr2 ], if either is string, it assumes 0 value
Is it true ??
Can I get it working with 'integer' comparison ??