当前位置: 技术问答>linux和unix
SHELL 2个数相等,这个判断如何写?
来源: 互联网 发布时间:2015-10-21
本文导语: #!/bin/sh set num = 8 echo $num #这个判断如何写? if test $num -ge 8 then echo "num is 8" else echo "num is not 8" fi; ---------------------------------------------------------------------- [zhousm@work test]$ sh scout scout: line 7: test: -ge: un...
#!/bin/sh
set num = 8
echo $num
#这个判断如何写?
if test $num -ge 8
then
echo "num is 8"
else
echo "num is not 8"
fi;
----------------------------------------------------------------------
[zhousm@work test]$ sh scout
scout: line 7: test: -ge: unary operator expected
num is not 8
[zhousm@work test]$
set num = 8
echo $num
#这个判断如何写?
if test $num -ge 8
then
echo "num is 8"
else
echo "num is not 8"
fi;
----------------------------------------------------------------------
[zhousm@work test]$ sh scout
scout: line 7: test: -ge: unary operator expected
num is not 8
[zhousm@work test]$
|
if [ condition ]
then
action
elif [ condition2 ]
then
action2
.
.
.
elif [ condition3 ]
then
else
actionx
fi
then
action
elif [ condition2 ]
then
action2
.
.
.
elif [ condition3 ]
then
else
actionx
fi
|
这个我知道,呵呵
if [ 0 -ne $num ] ; then
action
fi
if [ 0 -ne $num ] ; then
action
fi
|
-ne
|
if $num -ge 8
|
#!/usr/bin/ksh
num=9
if [ $num -ge 0 ]; then
echo "$num is not less than 8"
else
echo "$num is not bigger than 8"
fi;
num=9
if [ $num -ge 0 ]; then
echo "$num is not less than 8"
else
echo "$num is not bigger than 8"
fi;
|
#!/bin/sh
num=8
if test $num -eq 8
then
echo "num is equal to 8"
else
echo "num is not equal to 8"
fi
建议看一下test的man手册,对各种条件比较方式都有说明。
num=8
if test $num -eq 8
then
echo "num is equal to 8"
else
echo "num is not equal to 8"
fi
建议看一下test的man手册,对各种条件比较方式都有说明。