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 '
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
命令:./if.sh 2 1
结果:2 !=(-ne) 1
2 >(-gt) 1
转自:红联Linux
-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 '
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
命令:./if.sh 2 1
结果:2 !=(-ne) 1
2 >(-gt) 1
转自:红联Linux
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15142212/viewspace-558229/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15142212/viewspace-558229/
本文详细介绍了Linux shell脚本中if语句的使用方法,并通过示例展示了如何使用不同的比较运算符来判断数值关系,包括等于、不等于、小于、小于等于、大于及大于等于。
735

被折叠的 条评论
为什么被折叠?



