Tag name:bash

Sleeping until top of the minute

23rd June 2017

I recently wanted my bash script (running on Ubuntu) to sleep until the top of the minute. The suggested code snippet from goggling is:

sleep $((60 - $(date +%S) ))

This works well, unless the current seconds count is 08 or 09. Bash interprets numbers starting with 0 as octal and 08 (and 09) are not valid octal numbers. I fixed this in my script as follows:

sleep $((160 - 1$(date +%S) ))