Here I see the [[
allows comparison between string and integer.
[usr1@host dir]$ echo $count1
[1] "0"
[usr1@host dir]$ echo $count2
13188
[usr1@host dir]$ if [[ $count1 -ne $count2 ]]
> then
> echo "NE"
> fi
bash: [[: [1] "0": syntax error: operand expected (error token is "[1] "0"")
#this worked fine at one point
if [[ $count1 -ne $count2 ]] then
echo "NE"
fi
syntax error near unexpected token 'then'
if [[ $count1 -ne $count2 ]]; then
echo "NE"
fi
[[: [1] "0": syntax error: operand expected (error token is "[1] "0"")
I am very confused with the way the syntax works. How do we tackle different scenarios? How to prevent the syntax errors irrespective of the value changes(im guessing thats the reason it gives error now).
$count1
value really include brackets and quotes? What sort of result do you expect from input like that? (2) In your first example, the]]
and thethen
are on different lines. If you put them on the same line, you must put a;
between them. – G-Man Says 'Reinstate Monica' Dec 19 '18 at 05:54count1
. Will try again.. Thanks – sjd Dec 19 '18 at 06:21count1
is really:[1] "0"
, then!=
should be used inif
condition to compare thestring
and anumber
. Eg:if [[ "$count1" != "$count2" ]] ;then echo "NE"; fi
– ashish_k Dec 19 '18 at 06:42