3

I am trying to do arithmetic as I assign a variable a value. When the script reaches end_day it cannot do the math, and when I test it in the terminal it will simply return the expression. What do I need to do to get a result assigned to the variables.

Here is part of the script, $fhour comes from elsewhere and is simply a two digit number.

#Date variables
export start_year=$(date -u +%Y)
export start_mon=$(date -u +%m)
export start_day=$(date -u +%d)
export start_hour=$fhour
export end_year=$(date -u +%Y)
export end_mon=$(date -u +%m)
export end_day=${$start_day+(((($start_day*24)+84)/24)-((($start_day*24)+84)%24))}
export end_hour=${($start_day*24+84)%24}

Thanks for any help!

WxPilot
  • 1,946

1 Answers1

3

Following the guide of Cyberciti for bash arithmetic you are not using the correct method. To make arithmetics operations this is the format:

$((expression))

So in your case this would be the right variable assignment:

export end_day=$(( $start_day+(((($start_day*24)+84)/24)-((($start_day*24)+84)%24)) ))
export end_hour=$(( ($start_day*24+84)%24 ))

NOTE: this need to be tested, not sure if results are correct.

Lucio
  • 19,191
  • 32
  • 112
  • 191