bash - 如何根据 bash shell 脚本中输入的年份和月份(不是当前月份)获取过去 6 个月的年份和月份?
问题描述
这是一些代码,我试过了。我需要根据输入的年份和月份获取过去 6 个月的数据(年份和月份)。
输入和输出格式:-
*/example program:
please enter year:2019
please enter month:05
output:
201904
201903
201902
201901
201812
201811/*
我的脚本:
if [ -z $1 ]
then
echo Please enter year.
exit
fi ,
if [ -z $2 ]
then
echo Please enter month
exit
fi ,
x=0
while [ "$x" -le 12 ]
do
year= date +'%Y%m' -d "$x month ago"
echo $year
((x++))
解决方案
try
date --date="$1-$2-01 -6 month" +%B
Demo:
date --date="2019-05-01 -6 month" +'6 month from date was %B!'
6 month from date was November!
推荐阅读
- javascript - 在 chrome 扩展中单击外部时如何关闭/关闭 default_popup?
- sql-server - 查询表数据,字段相互关联
- redux - 如何从共享首选项设置 initialState?
- raku - 有没有办法从 Perl6 模块代码中的 META6.json 获取版本?
- sql-server - 使用 NamedParamterJdbcTemplate 时,简单查询大约需要 2 秒。从 SQL DB,花费不到 100 毫秒
- r - R中magrittr和arima的兼容性问题
- wpf - 在 DataGridNumericUpDownColumn 上将字符串格式设置为无逗号
- node.js - 无法在 Protractor Cucumber 框架中的 webElements 上单击或发送键
- matlab - 使用 MATLAB 从 Openweathermap.org 抓取数据
- regex - 清除除匹配项之外的所有内容