shell 程序设计入门 比较两个数的大小
2011-12-10 15:44
555 查看
shell 程序设计入门
[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
都有空格
#!/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
都有空格
相关文章推荐
- 编写一个程序 用宏实现两个数的比较大小
- 使用C语言编写程序,求两个整数的较大值(随机输入两个数,比较大小)
- 程序设计基本概念——比较变量大小
- shell脚本下比较两个数的大小
- shell脚本编写比较两个数的大小
- 5.编写一个程序,有两个类,其中类MAX中具有两个方法,方法名都是max,一个方法能够比较两个数的大小,另外一个方法能够比较三个数的大小。在另外一个类中创建对象,调用这两个方法,分别输出两组数:2、6
- C语言小试牛刀两个初级程序练习------1到100的加法运算,两个数大小的比较
- HDU 2054 字符串 比较两个数大小,忽略整数前面的0和小数最后的0
- 比较两个数大小(位运算)
- Linux程序设计-学习笔记-第二章shell程序设计
- shell基于小数大小比较
- shell脚本之比较文件大小
- shell中比较字符串大小,>和<前需要加上\进行转义,否则会输出到文件了
- 程序设计竞赛ACM训练手册 从入门到精通
- Shell比较两个日期的大小
- CodeForces - 616A Comparing Two Long Integers (模拟)比较两个数大小
- 不用if比较两个数大小
- 比较两个数大小的各种方法
- YTU-OJ-Problem L: 熟悉题型——自由设计(比较大小-类模板)
- 实现两个数大小的比较