9
Mar
Posted by Derek@TheDailyLinux in Scripting » 2 Comments »
Script to Calculate Number of Hours from Minutes
The following is a quick script that will convert minutes to hours and minutes as well as total hours in decimal form (1 hour, 30 minutes is 1.5 hours). Simply save the contents of the script below to a file, execute chmod +x filename on that file, and then run it with ./filename. Feel free to modify it to fit your needs.
#!/bin/sh minutes=432 hrs=`echo "$minutes / 60" | bc` min=`echo "$minutes % 60" | bc` if [ $min -gt 0 ]; then if [ $min -le 2 ]; then hours=`echo "$hrs + .0" | bc`; fi if [ 3 -le $min -a $min -le 8 ]; then hours=`echo "$hrs + .1" | bc`; fi if [ 9 -le $min -a $min -le 14 ]; then hours=`echo "$hrs + .2" | bc`; fi if [ 15 -le $min -a $min -le 20 ]; then hours=`echo "$hrs + .3" | bc`; fi if [ 21 -le $min -a $min -le 26 ]; then hours=`echo "$hrs + .4" | bc`; fi if [ 27 -le $min -a $min -le 32 ]; then hours=`echo "$hrs + .5" | bc`; fi if [ 33 -le $min -a $min -le 38 ]; then hours=`echo "$hrs + .6" | bc`; fi if [ 39 -le $min -a $min -le 44 ]; then hours=`echo "$hrs + .7" | bc`; fi if [ 45 -le $min -a $min -le 50 ]; then hours=`echo "$hrs + .8" | bc`; fi if [ 51 -le $min -a $min -le 56 ]; then hours=`echo "$hrs + .9" | bc`; fi if [ 57 -le $min -a $min -le 60 ]; then hours=`echo "$hrs + 1.0" | bc`; fi fi echo "Minutes Entered: $minutes" echo "$hrs Hours, $min Minutes ($hours Hours)"
Please let us know if you think you have a better solution or have a suggestion by using the commenting system below.
Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:
Here are some similar posts that you may be interested in:
There's 2 Comments So Far
June 4th, 2012 at 7:25 pm
awk ‘BEGIN { print 1234/60 }’
August 24th, 2012 at 1:11 am
#!/bin/sh
minutes=432
hrs=`echo “$minutes / 60″ | bc`
min=`echo “$minutes % 60″ | bc`
hours=`echo “scale=2; $hrs + $min/60″ | bc`
echo “$hrs Hours, $min Minutes ($hours Hours)”
Share your thoughts, leave a comment!