'How can we compare the time format such that [ 00:00:10 and 00:00:22 ]?
I have the execution times of program which are like so 00:00:10, 00:30:23
The question is how can I compare them to each other?
val1="00:00:10"
val2="00:30:23"
if [ "$val1" -gt "$val2" ]; then
echo "bigger"
else
echo "smaller"
fi
this give an error that they are not INTEGERS.
So, when I changed the code without -gt to > it does not work too..
Could you let me know how can we compare the time formats such that I explained above ?
Thank a lot..
Solution 1:[1]
You can instead use [[ "$val1" > "$val2" ]] to compare dates:
?$ if [[ 00:00:10 > 00:30:23 ]]; then echo yes; else echo no; fi
no
?$ if [[ 00:00:10 < 00:30:23 ]]; then echo yes; else echo no; fi
yes
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
