赞
踩
1. 简单实用长度判断
- #!/bin/bash
- dt="$1"
- echo "dt is: $dt"
- len_dt=${#dt}
- echo "len dt is: $len_dt"
- trim_dt=${dt//-/}
- echo "trim_dt is $trim_dt"
- len_trim_dt=${#trim_dt}
- echo "len_trim_dt is $len_trim_dt"
- len_dur=`echo $(($len_dt-$len_trim_dt))`
- echo "len_dur is $len_dur"
-
- if [ 2 -eq $len_dur ]
- then
- echo "eq 2"
- dt=`date -d "$dt" +"%Y-%m-%d"`
- echo $?
- else
- echo "not eq"
- fi
二、月初执行脚本
- #!/bin/bash
-
- start_dt=$1
- end_dt=$2
-
- #echo "day id : "${start_dt:8:2}
-
- while [ "${start_dt}" != "`date -d "${end_dt} +1 day" +"%Y-%m-%d"`" ]
- do
- if [ ${start_dt:8:2} = 01 ];
- then
- echo ${start_dt} "do business here"
- fi
- start_dt=`date -d "${start_dt} +1 day" +"%Y-%m-%d"`
- done
-
- echo "=========>>>>>>>> exit with $?"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。