Results 1 to 6 of 6
i can not understand why the command after else never executed even if the size is less than num
#! /bin/bash
num="63%"
size=$(df -h |grep home|awk -F " " '{print ...
- 05-21-2010 #1Just Joined!
- Join Date
- Sep 2009
- Posts
- 4
script problem
i can not understand why the command after else never executed even if the size is less than num
#! /bin/bash
num="63%"
size=$(df -h |grep home|awk -F " " '{print $5}')
if [ "$size">="$num" ];then
echo $size
echo "toto"
else
echo "sorry"
echo $num
fi;
please help me
- 05-21-2010 #2Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
$size and $num are string values and are not friendly to arithmetics. You must strip the '%' sign from them.
Use ' -gt ' instead instead of '>=' for integer comparison.0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 05-21-2010 #3Just Joined!
- Join Date
- Sep 2009
- Posts
- 4
but you must know that the resuld of size is in percentage
size=$(df -h |grep home|awk -F " " '{print $5}')
(this command gives the result in %)
so how can i compare those two percentage values?
- 05-21-2010 #4Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
You must strip the '%' signCode:... num=62 ... size=${size%'%'} #HERE YOU KEEP EVERYTHING EXCEPT THE LAST CHARACTER ... if [ $size -gt $num ]; then ...0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 05-21-2010 #5Just Joined!
- Join Date
- Sep 2009
- Posts
- 4
thanks a lot ,every thing is ok. now can i have your mail in order to keep in touch
- 05-21-2010 #6Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
Loooooooooool !
0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.


Reply With Quote