This question already has an answer here:
- Quickly calculate date differences 14 answers
I have two time variables in bash. I am trying to find a way to get the time difference between the two.
Yes, I have read many many many examples on the net, but they do not seem to have a "simple" solution. Rather, it seems as if time arithmetic in Bash was an "afterthought".
Here are some of the links I have read: Link 1
It would appear as if there is no "elegant" solution for it (my opinion).
So my variables are like the following:
TIME_START="date +%H:%M:%S //Start of script // The script TIME_END="date +%H:%M:%S //End of script
So I am trying to get the elapsed time. The script can take up to 3 hours to execute (interacting with sensors and hardware etc.). The
TIME_START variable gets inserted into MySQL and later retrieved by Bash (when the script ends) in order to do the "elapsed time" calculation.
I have read somewhere that the following code would work, but it did not:
diff=$(expr $TIME_END - $TIME_START) echo $diff