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..
CodePudding user response:
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