ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux Shell下变量比较

Linux Shell下变量比较

原创 Linux操作系统 作者:dbasdk 时间:2014-11-18 12:50:05 0 删除 编辑
两个参数对比


[root@CentOS6 shell]# vi test.sh
[root@CentOS6 shell]# cat test.sh
#!/bin/bash
if [ $1 -ge $2 ];
 then echo -e "\033[41;37m <参数不对,第一个数字要小于第二个,退出此次操作!> \033[0m"
else
 echo "起止时间依次是:`date -d "$2 days ago" +%Y%m%d`--`date -d "$1 days ago" +%Y%m%d`";
fi
[root@CentOS6 shell]# ./test.sh 1 2
起止时间依次是:20141116--20141117
[root@CentOS6 shell]# ./test.sh 2 1
 <参数不对,第一个数字要小于第二个,退出此次操作!>
[root@CentOS6 shell]# ./test.sh 2 8
起止时间依次是:20141110--20141116
[root@CentOS6 shell]# ./test.sh 1 90
起止时间依次是:20140820--20141117
[root@CentOS6 shell]# ./test.sh 1 100
起止时间依次是:20140810--20141117
[root@CentOS6 shell]# ./test.sh 1 1
 <参数不对,第一个数字要小于第二个,退出此次操作!>
[root@CentOS6 shell]#

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29734436/viewspace-1337421/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-02

  • 博文量
    490
  • 访问量
    1388144