#!/bin/bash
var1=0
x=1
while [ $x -lt 10 ]
do
echo "Welcome $x times"
var1=$(prstat -Lc 1 1 | nawk ' /^Total/ {print substr($8,1,length($8)-1)}')
echo "$var1"
if [ $var1 -gt 4 ]
then
break
fi
sleep 6
x=$(( $x + 1 ))
done
giving output:
bash-3.00$ ./ch1.sh
Welcome 1 times
5.90
./ch1.sh: line 9: [: 5.90: integer expression expected
Welcome 2 times
5.75
./ch1.sh: line 9: [: 5.75: integer expression expected
Welcome 3 times
5.64
./ch1.s
...
..
Please help.....
I am using KSH
use > symbol to compar
bash-3.00$ [ $PI > 5 ] && echo "High" || echo "Less"
High
bash-3.00$ [ "$PI" > "5" ] && echo "High" || echo "Less"
High
bash-3.00$ [ $PI -gt 5 ] && echo "High" || echo "Less"
bash: [: 3.14: integer expression expected
Less
giving same error
#!/bin/bash
var1=0
x=1
while [ $x -lt 10 ]
do
echo "Welcome $x times"
var1=$(prstat -Lc 1 1 | nawk ' /^Total/ {print substr($8,1,length($8)-1)}')
echo "$var1"
if [ "$var1" -gt 9 ]
then
break
sleep 6
fi
x=$(( $x + 1 ))
done
O/p
Welcome 1 times
2.53
./ch1.sh: line 9: [: 2.53: integer expression expected
Welcome 2 times
2.52
./ch1.sh: line 9: [: 2.52: integer expression expected
Welcome 3 times
2.52
./ch1.sh: line 9: [: 2.52: integer expression expected
Welcome 4 times
2.51
yazu
June 23, 2011, 7:58am
5
You should convert this value to integer like this:
% var=2.52
% echo ${var%.*}
2
% var=$(printf "%.0f\n" $var); echo $var
3
hey guys It is still not working plz help...
#!/bin/bash
x=1
while [ $x -lt 10 ]
do
echo "Welcome $x times"
var1=$(prstat -Lc 1 1 | nawk ' /^Total/ {print substr($8,1,length($8)-1)}')
echo "$var1"
var=$(printf "%.0f\n" $var);
echo "$var1"
if ( $var1 -gt 10 )
then
break
fi
sleep 1
x=$(( $x + 1 ))
done
O/p
Welcome 1 times
6.42
6.42
./ch1.sh: line 10: 6.42: command not found
Welcome 2 times
6.42
6.42
./ch1.sh: line 10: 6.42: command not found
Welcome 3 times
6.42
6.42
./ch1.sh: line 1....
why you are not using > symbol ?
if I have used > I am getting error
o/p
bash-3.00$ ./ch1.sh
Welcome 1 times
4.61
4.61
./ch1.sh: line 10: 10: Permission denied
Welcome 2 times
4.62
4.62
./ch1.sh: line 10: 10: Permission denied
Welcome 3 times
4.62
4.62
./ch1.sh: lin
use the if condition like this
if [ $var1 > 10 ] # use square brackets
Thanks.... Got solved using this command
if [ $var2 -gt 10 ]