bash - 如何对 MM/DD/YYYY 格式的日期进行数学运算?
问题描述
我有一个包含MM/DD/YYY
格式日期列表的文件。这些中的每一个都存储在$date_variable
一个while循环中。我也有:
current_date="$( date +%x )"
我需要将文件中的日期与$current_date
.
我怎么能说“如果当前日期 = $date_variable + 至少 7 天?或者”如果自 $date_variable 以来至少已经过去了 7 天,那么就这样做”。
我曾尝试使用“if”比较运算符,但由于$date_variable
.
此外,我发现很难更改 的格式,$date_variable
因为它们是从带有curl
和的网页中获取的grep
。
编辑:
我的脚本如下所示:
# Store current date in the MM/DD/YYYY format
current_date="$( date +%x )"
# Iterate each line from hotfix_final and read the variables hf_link and release_date
while read -r hf_link release_date; do
# Install hotfixes on POC machines
if [ "$current_date" > "$release_date" ]; then
wget "$hf_link"
fi
done </home/abc/hotfix_final # Set the file as input for the whole while loop
hotfix_final:
https://download.abc.com/hotfix 06/24/2019
https://download.abc.com/hotfix2 06/26/2019
我想说:
if "$current_date" = "$release_date" + at least 7 days; then ...; fi
解决方案
推荐阅读
- swift - 关于为什么我的数据没有被传递到新的表格视图的任何想法?
- c# - 在 .NET Core 中进行没有依赖注入的 HTTP 调用
- angular - 赛普拉斯测试在 Angular 中的十六进制颜色失败
- excel - 使用列字母的字符串变量设置范围
- android - 为什么 ./gradlew :processDebugUnitTestManifest 失败?
- python - “NoneType”对象没有属性“register_forward_hook”错误
- python - 尝试构建 pyLucene 时收到 KeyError: 'darwin'
- java - 检查给定格式字符串可用于解析的 Temporal 类型
- python - 在 Python 中将 float 转换为 int 结果错误答案
- matlab - 如何防止轴关闭删除字幕?