I have these two funtions in my bash script
function start_time {
unset date1
date1=$(date +"%s")
}
function stop_time {
unset date2 diff minutes seconds hours varhours varminutes varseconds
date2=$(date +"%s")
diff=$(($date2-$date1)) # <-- There is seconds
minutes=$((($diff / 60)))
seconds=$((($diff % 60)))
hours=$((($minutes / 60)))
if [ $hours != 0 ]; then varhours=$(echo "$hours Hours"); fi
if [ $minutes != 0 ]; then varminutes=$(echo "$minutes Minutes"); fi
if [ $seconds != 0 ]; then varseconds=$(echo "$seconds Seconds"); fi
echo "++ $1 : $varhours $varminutes $varseconds "
}
So I execute them in the following way;
start_time
"some bash job for example sleep command for a while"
stop_time "execution time was"
If the script takes for example, 3 hrs 23 minutes 50 seconds, it shows of the following way the output
execution time was : 3 hours 203 minutes and 50 seconds
So, my question is, whether there is some way to show the correct minutes, i mean the 123 minutes are the total time that the script took in execute some job, so the expected output must be : 3 hours 23 minutes 50 seconds.