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

来源:互联网 发布:上海软件中心 编辑:程序博客网 时间:2024/05/17 16:00
shell 程序设计入门
#!/bin/sh#The function used to compare the two numbersvara=$1varb=$2if [ -z $vara ] || [ -z $varb ]thenecho "please input hte two numbers"exit 1fiif [ $vara -eq $varb ] ; thenecho "the $vara = $varb"else if [ $vara -gt $varb ]thenecho "the $vara > $varb"elif [ $vara -lt $varb ]thenecho "the $vara < $varb"     fifi


[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

都有空格

 

原创粉丝点击