Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

how to calculate duration of time in shell script

#!/usr/bin/env bash
# 1 method
SECONDS=0
# do some work
duration=$SECONDS
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."

# 2 method
string1="10:33:56"
string2="10:36:10"
StartDate=$(date -u -d "$string1" +"%s")
FinalDate=$(date -u -d "$string2" +"%s")
date -u -d "0 $FinalDate sec - $StartDate sec" +"%H:%M:%S"

# 3 method
START=$(date +%s);
sleep 1; # Your stuff
END=$(date +%s);
echo $((END-START)) | awk '{print int($1/60)":"int($1%60)}'
Comment

PREVIOUS NEXT
Code Example
Shell :: storybook vite installtion 
Shell :: tcr test commit revert 
Shell :: oracle docker images 
Shell :: k8s dashboartd 
Shell :: pecl install specific version 
Shell :: change permission to connect your SSH instance mac 
Shell :: use rebase in git command 
Shell :: ubuntu set desktop as default bashrc 
Shell :: gpg send key 
Shell :: how to change elementary os theme 
Shell :: linux bash assign variable and print to console 
Shell :: git auto sign 
Shell :: cmd line install team viever 
Shell :: nano add line numbers 
Shell :: installing ipython-sql command line 
Shell :: connect to a vm from cloudshell 
Shell :: how to install python using windows command prompt 
Shell :: how to highlight code in github editor 
Shell :: docker on linux 
Shell :: create windows network share from command line 
Shell :: git how to not commit but keep changes 
Shell :: bash command to move all files to a dir 
Shell :: create a new repository on the command line on GitHub 
Shell :: how to permanently install wifi drivers realtek 8723de in ubuntu 18.04 
Shell :: remove multiple files powershell 
Shell :: scss You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders 
Shell :: uninstall g2o 
Shell :: vi replace 
Shell :: sudo rename command 
Shell :: linux mint 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =