使用日期获取Bash中的明天日期 [英] Using date to get tomorrows date in Bash

查看:41
本文介绍了使用日期获取Bash中的明天日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个bash脚本,该脚本将在给定的条件下运行,但要处理第二天的日期数据,我目前的方法是获取unix时间戳并为其添加一整天的秒数,但是我无法使其正常工作,还没有找到我在网上寻找的东西.

I want to write a bash script that will run on a given but process data with next days date, My current approach is to get the unix time stamp and add a days worth of seconds to it, but I cant get it working, and haven't yet found what I'm looking for online.

这是我尝试过的方法,我觉得问题是它的字符串不是数字,但是我对bash的了解不足以确保,这是正确的吗?以及我该如何解决?

Here's what I've tried, I feel like the problem is that its a string an not a number, but I dont know enough about bash to be sure, is this correct? and how do I resolve this?

today="$(date +'%s')"

tomorrow="$($today + 86400)"

echo "$today"

echo "$tomorrow"

推荐答案

$(...)是命令替换.您正在尝试将 $ today + 86400 作为命令运行.

$(...) is command substitution. You're trying to run $today + 86400 as a command.

$((...))是算术扩展.这就是您要使用的.

$((...)) is arithmetic expansion. This is what you want to use.

tomorrow=$(( today + 86400 ))

另请参阅 http://mywiki.wooledge.org/ArithmeticExpression ,以了解有关在外壳.

Also see http://mywiki.wooledge.org/ArithmeticExpression for more on doing arithmetics in the shell.

这篇关于使用日期获取Bash中的明天日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆