Linux中if语句的使用
常用运算符
-eq ==
-ne !=
-lt <
-le <=
-gt >
-ge >=
编写一脚本if.sh
#!/bin/sh
if test $1 -eq $2; then
echo $1 '==(-eq)' $2
else
if test $1 -ne $2;then
echo $1 '!=(-ne)' $2
fi
if test $1 -lt $2;then
echo $1 '<(-lt)' $2
fi
if test $1 -gt $2;then
echo $1 '>(-gt)' $2
fi
fi
运行如下
chmod a+x if.sh
命令:./if.sh 2 2
结果:2 ==(-eq) 2
命令:./if.sh 1 2
结果:1 !=(-ne) 2
1 <(-lt) 2
命令:./if.sh 2 1
结果:2 !=(-ne) 1
2 >(-gt) 1
转自:红联Linux
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15142212/viewspace-558229/
,如需转载,请注明出处,否则将追究法律责任。