The date
command is not part of bash. It's provided by your operating system, and its behaviour differs in different operating systems. Notably, GNU coreutils date (in most Linux distros) has a -d
option used for interpreting source dates, whereas BSD date has a -f
option for interpreting specifically formatted input dates and a -v
option for adjusting times by various units.
You've already got an accepted answer for the Linux option. To be complete about this, here's a BSD (and macOS) option:
$ for (( s=0; s<86400; s+=610 )); do date -j -v+${s}S -f '%H:%M:%S' "$time" '+%T'; done | head -5
00:00:00
00:10:10
00:20:20
00:30:30
00:40:40
Output here is obviously trimmed to 5 lines.
Of course, this is still platform-specific. If you want something that will work with bash anywhere, then as long as you're using bash >4.2, the following might do:
$ offset=$(printf '%(%z)T\n' 0)
$ for (( s=$(( ${offset:1:2}*3600 + ${offset:3}*60 )); s<86400; s+=610 )); do printf '%(%T)T\n' "$s"; done | head -5
00:00:00
00:10:10
00:20:20
00:30:30
00:40:40
The $offset
variable allows us to compensate for the fact that you may not be in UTC. :) Like the date
solution, this steps through increments of 610 seconds, but it uses printf
's %T
format to generate output. You may with to add or subtract the timezone offset to the 86400 end point to get a full day of times. Handling that is left as an exercise for the reader. :-)