Say I have a bunch of time stamps
As I iterate over these timestamps,
01:23:00
12开发者_开发问答:34:14
17:09:12
...
I want to include only timestamps between 08:00:00 and 17:00:00
please suggest
You can do a simple string comparison:
if [[ "$timestamp" > "08:00:00" && "$timestamp" < "17:00:00" ]]
If you want to include the ends of your range, you'll have to test for that separately since Bash doesn't have a >=
or <=
operators for strings:
start="08:00:00"
end="17:00:00"
if [[ "$timestamp" == "$start" ||
"$timestamp" > "$start" && "$timestamp" < "$end" ||
"$timestamp" == "$end" ]]
精彩评论