0514-86177077
9:00-17:00(工作日)
一、創(chuàng)建測試文件test.sh
#!/bin/sh . /etc/profile # 參數(shù): # args[0] ,數(shù)據(jù)日期,日期格式y(tǒng)yyy-MM-dd # 取30天以前的日期 function get_date_30daysbefore() { sec=`date -d $1 +%s` sec_30daysbefore=$((sec - 86400*30)) days_before=`date -d @$sec_30daysbefore +%F` echo $days_before } if [ $# == 1 ]; then today=$1 dates_30=`get_date_30daysbefore $1` else today=`date -d -1days '+%Y-%m-%d'` dates_30=`date -d -30days '+%Y-%m-%d'` fi echo $today echo $dates_30
二、無參運行
## 不帶參數(shù),從當前時間開始算 $ ./test.sh 2016-10-28 2016-09-29
三、傳參運行
$ ./test.sh 2015-10-29 2015-10-29 2015-09-29
總結
以上就是利用shell獲取指定日期前N天日期的全部內容,希望本文的內容對大家的學習或者工作能有所幫助,如果有疑問大家可以留言交流。
標簽:優(yōu)質小號 武漢 百色 鎮(zhèn)江 滁州 六盤水 自貢 丹東
上一篇:每天一個linux命令之locate 命令
下一篇:Linux vim編輯命令模式
Copyright ? 1999-2012 誠信 合法 規(guī)范的巨人網(wǎng)絡通訊始建于2005年
蘇ICP備15040257號-8