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.
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"
You can try below
Set your timezone, then run
date
.E.g.
Alternatively, I'd use perl:
This will output
Some of the answers for this question depend on having GNU date installed. If you don't have GNU date, you can use the built-in
date
command with the-v
option.The command
$ date -v+1d
returns tomorrow's date.
You can use it with all the standard
date
formatting options, so$ date -v+1d +%Y-%m-%d
returns tomorrow's date in the format YYYY-MM-DD.
$(...)
is command substitution. You're trying to run$today + 86400
as a command.$((...))
is arithmetic expansion. This is what you want to use.Also see http://mywiki.wooledge.org/ArithmeticExpression for more on doing arithmetics in the shell.
If you have
gnu-date
then to get next day you can just do: