I have this code:
printf -v s '%(%S)T' -1 # grab the current second
if ((s == 0)); then
# at the top of the minute, run some code
fi
This code throws an error on the eighth and ninth second of every minute:
bash: ((: 08: value too great for base (error token is "08")
bash: ((: 09: value too great for base (error token is "09")
How can I rectify this? Basically, we need to suppress the leading zero in the date output generated by printf
.
Use a
-
prefix in the format string, thus:This suppresses the leading zero.
A more generic way of solving this is to specify the base in Bash arithmetic this way, while keeping the
printf
command unchanged:Related post on Unix & Linux Stack Exchange: