您的位置:首页 > 运维架构 > Shell

shell 程序设计入门 比较两个数的大小

2011-12-10 15:44 555 查看
shell 程序设计入门
#!/bin/sh
#The function used to compare the two numbers
vara=$1
varb=$2
if [ -z $vara ] || [ -z $varb ]
then
echo "please input hte two numbers"
exit 1
fi

if [ $vara -eq $varb ] ; then
echo "the $vara = $varb"
else if [ $vara -gt $varb ]
then
echo "the $vara > $varb"
elif [ $vara -lt $varb ]
then
echo "the $vara < $varb"
fi
fi


[root@localhost sourcetemp]# ./compare 1 2

the 1 < 2

[root@localhost sourcetemp]# ./compare 4 3

the 4 > 3

[root@localhost sourcetemp]# ./compare 3 3

the 3 = 3

需要注意的:

1.#!/bin/bash 写成 #!bin/bash 找不到解析

2.#!/bin/bash 可写成 #!/bin/sh sh 连接到 bash

3.if [ $var -eq $varb ] ; then

都有空格

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell function bash input