您现在的位置是:网站首页> 编程资料编程资料
利用shell获取指定日期前N天的日期_linux shell_
2023-05-26
369人已围观
简介 利用shell获取指定日期前N天的日期_linux shell_
一、创建测试文件test.sh
#!/bin/sh . /etc/profile # 参数: # args[0] ,数据日期,日期格式yyyy-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二、无参运行
## 不带参数,从当前时间开始算 $ ./test.sh 2016-10-28 2016-09-29
三、传参运行
$ ./test.sh 2015-10-29 2015-10-29 2015-09-29
总结
以上就是利用shell获取指定日期前N天日期的全部内容,希望本文的内容对大家的学习或者工作能有所帮助,如果有疑问大家可以留言交流。
相关内容
- 每天一个linux命令之locate 命令_linux shell_
- Linux下JDK中文字体乱码的解决方法_linux shell_
- Linux用户配置sudo权限(visudo)的方法_linux shell_
- Ubuntu配置NFS的具体流程(推荐)_linux shell_
- php在linux中可能用到的命令(推荐)_linux shell_
- linux下安装配置Memcache和PHP环境的实现_linux shell_
- 详解Linux命令中的正则表达式_linux shell_
- linux shell发送Email邮件的方法详解_linux shell_
- Linux shell命令帮助格式详解_linux shell_
- Log4j 日志文件Linux/Mac/Windows通用存放位置设置方法_linux shell_
