2009年9月16日 星期三

Bash string compare greater less

比較字串順序大小用 \> 及 \<,大於等於或小於等於要用 ! 配合來實作。

if [ $str \> $str2 ]; then
echo "greater"
fi

if [ ! $str \< $str2 ]; then
echo "greater or equal"
fi

實例應用:
g_host_os_ver=`uname -r`
if [ ! $g_host_os_ver \< "2.6.28" ]; then
ko=$(echo $ko|sed 's/^\///g') # remove the first /
fi

沒有留言:

張貼留言