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.
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.
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