-1
now=$(date +"%r")

$now has the current time in 12hr format. I need to add configurable minutes to now and save it in an another variable. Please help.

Preet
  • 984
  • 2
  • 14
  • 34
Meghashyam
  • 53
  • 2
  • 6
  • Please avoid *"Give me the codez"* questions that have been asked and answered so many times you have to make an effort to avoid finding an answer. Instead show the script you are working on and state where the problem is. Also see [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/608639) – jww Aug 03 '18 at 07:12

1 Answers1

1

It is quite easy to do the GNU date using the -d option.

(however you will want to change the variable name from now to something else as now is a keyword in -d "datestring" processing)

For example:

foo=$(date +%r)        ## save current time in your format in foo
addmin=10              ## variable to add minutes to the time (10 here)
bar=$(date -d "$foo + $addmin minutes" +%r)  ## add minutes to time saving in bar
printf "foo: %s\nbar: %s\n" "$foo" "$bar"    ## output both

Example Output

foo: 09:14:53 PM
bar: 09:24:53 PM
David C. Rankin
  • 81,885
  • 6
  • 58
  • 85