veh*_*zzz 2 linux bash scripting
说我有一堆时间戳
当我迭代这些时间戳时,
01:23:00
12:34:14
17:09:12
...
Run Code Online (Sandbox Code Playgroud)
我想在08:00:00到17:00:00之间只包含时间戳
请建议
你可以做一个简单的字符串比较:
if [[ "$timestamp" > "08:00:00" && "$timestamp" < "17:00:00" ]]
Run Code Online (Sandbox Code Playgroud)
如果你希望在你的范围的两端,你要测试的是分别,因为击不具有>=或<=运营商的字符串:
start="08:00:00"
end="17:00:00"
if [[ "$timestamp" == "$start" ||
"$timestamp" > "$start" && "$timestamp" < "$end" ||
"$timestamp" == "$end" ]]
Run Code Online (Sandbox Code Playgroud)