shell date处理

xyang@xyang-Latitude-E5440:~$ cat test.sh 
#!/bin/bash

today=$(date +%F)

if [ -n "$1" ];then
   today=$1
fi

yesterday=$(date -d "${today} -1 day" +%F)
afterweek=$(date -d "${today} +7 day" +%F)
dt=$(date -d "${today} -1 day" +%Y%m%d)
beforeweek=$(date -d"${today} -7 day" +%F)

echo $today
echo $yesterday
echo $afterweek
echo $dt
echo $beforeweek
xyang@xyang-Latitude-E5440:~$ bash test.sh
2015-11-11
2015-11-10
2015-11-18
20151110
2015-11-04


你可能感兴趣的:(shell)