#1.判断是不是两个数
[ $# -ne 2 ] &&{
echo "Usage:$0 num1 num2"
exit 1
}
#2.判断是否为数字
expr $1 + $2 + 999 &>/dev/null
[ $? -ne 0 ] &&{
echo "请输入两个整数"
exit 2
}
if [ $1 -gt $2 ]
then
echo "$1>$2"
elif [ $1 -lt $2 ]
then
echo "$1<$2"
else
echo "$1=$2"
fi
========================
read -p "please two number: " a b
expr $a + $b + 999 &>/dev/null
if [ $? -ne 0 ]
then
echo "请输入两个整数"
exit 1
else
if [ $a -gt $b ]
then
echo "$a>$b"
elif [ $a -lt $b ]
then
echo "$a<$b"
else
echo "$a=$b"
fi
fi
Shell代码 #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin ram_max=9 ram=10.2 #ram大于ram_max打印出1赋值给变量check check=`echo $ram >$ram_max bc` #判断如果check匹配1打印1,注意空格(shell格式不正确会导致运行错误) if [ $check = 1 ] then echo 1 fi欢迎分享,转载请注明来源:内存溢出
评论列表(0条)