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
都有空格