shell输入指定日期参数,输出该日期的前一天和后一天
#!/bin/bash
c=$1
if [ $# == 1 ]; then
yesterday=`date -d "$c -1 day" +"%Y%m%d"`
echo $yesterday
tomorrow=`date -d "$c 1 day" +"%Y%m%d"`
echo $tomorrow
else
yesterday=`date -d yesterday +%Y%m%d`
echo $yesterday
tomorrow=`date -d tomorrow +%y%m%d`
echo $tomorrow
fi
带参数执行脚本 sh hhh.sh 20191001 执行结果如下:
不带参数执行脚本 sh hhh.sh 执行结果如下: