Convert time Seconds to Hours-Minutes-Seconds format – Shell Scripting – Video
I came across the situation, when i provide seconds it should print values in Hours, Minutes and Seconds. Directly How many seconds equals to how many Hours/Minutes/Seconds. We are going to see on small shell script which can calculate and do it for us. convert time seconds to Hours-Minutes-Seconds.
Convert time seconds to H:M:S
It is a simple bash script which will convert seconds to Hours:Minutes:Seconds format. convert time.
First method of script is below, i observed an issue while running same shell script in Ubuntu OS is not working Upended with second method using bc command
#!/bin/bash ##Author: Ankam Ravi Kumar ##Date: 10th July 2017 ##Convert Seconds to Hours:Minutes:Seconds Format Using this script ## Starting of Script ## [ -z ] && echo "Usage: $(basename $0) <seconds>" && exit||secs= _hms() { local S= ((h=S/3600)) ((m=S%3600/60)) ((s=S%60)) printf "%dh:%dm:%ds\n" $h $m $s } _hms ${secs} ## END Of Script##
Convert Time Seconds to Hours Minutes Seconds Shell Script
Please do comment your feedback is very important to us
#!/bin/bash ## Ankam Ravi Kumar ##Date: 11th July 2017 ##Seconds to Hours:Minutes:Seconds Format Using this script S=$1 if [ $1 -ge 1 ]; then H=`echo $S / 3600 | bc` M=`echo $S % 3600 / 60 | bc` S=`echo $S % 60 | bc` echo "H: $H M: $M S: $S" else echo "Usage: sh seconds.sh <seconds>" fi
Output of this convert Seconds shell script is below
# sh seconds.sh 8000 H: 2 M: 13 S: 20
Related Articles
Debug Shell Script Easily identify errors
What is Shell scripting Very Basic to Learn
Logical Volume Manager Step by Step Guide
Thanks for your wonderful Support and Encouragement