两个参数对比
[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]#
[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博客 ” ,链接:http://blog.itpub.net/29734436/viewspace-1337421/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29734436/viewspace-1337421/