Integer Expression Expected Error
by jitesh1788 from LinuxQuestions.org on (#5CPQD)
Hi All,
I am trying to execute below script and getting Integer Expression Expected Error:
ecount=`tail -1 countfile.txt`
ncount=580
echo "ecount=${ecount}"
echo "ncount=${ncount}"
if [ ${ecount}" -eq ${ncount}" ];
then
echo Count is matching"
else
echo count is not matching"
fi
Note: I have 580 in the countfile.txt.
I am assuming while doing tail -1 countfile.txt it returns 580 but its string hence wile comparing in If statement its giving this error.
I wanted to know how can I convert 580 coming from file to integer so that If statement works properly.
Any help is appreciated.


I am trying to execute below script and getting Integer Expression Expected Error:
ecount=`tail -1 countfile.txt`
ncount=580
echo "ecount=${ecount}"
echo "ncount=${ncount}"
if [ ${ecount}" -eq ${ncount}" ];
then
echo Count is matching"
else
echo count is not matching"
fi
Note: I have 580 in the countfile.txt.
I am assuming while doing tail -1 countfile.txt it returns 580 but its string hence wile comparing in If statement its giving this error.
I wanted to know how can I convert 580 coming from file to integer so that If statement works properly.
Any help is appreciated.