Hi,
I am new to shell/bash script. I am trying to run below script
#!/bin/bash
a=0
b=10
if [ $a == $b ]
then
echo "a is equal to be"
else
echo "a is not equal to be"
fi
MAX=10
while [ "$a" -lt $b ]
do
echo $a
a='expr $a + 1'
done
it is giving below error:
-bash-3.2$ sh cal.sh
a is not equal to be
0
cal.sh: line 11: [: expr $a + 1: integer expression expected
-bash-3.2$
Could you please any one help to solve the problem.
thanks,
Mallik
---------- Post updated at 12:40 PM ---------- Previous update was at 12:12 PM ----------
I have solved above problem by using below code
declare -i a
declare -i b
#!/bin/bash
declare -i a
declare -i b
a=0
b=10
if [ $a == $b ]
then
echo "a is equal to be"
else
echo "a is not equal to be"
fi
MAX=10
while [ "$a" -lt $b ]
do
echo $a
a=" $a + 1 "
done
---------- Post updated at 12:41 PM ---------- Previous update was at 12:40 PM ----------
solved the above problem
declare -i a
declare -i b