Remembering a classic “time travel” bug reminded me of a fun time in Bash. How to reproduce in four handy steps:
- Split a date string by hyphens into
$monthin an arithmetic context. I don’t remember the exact code, but it was probably something trivial like
[[ "$month" -eq 1 ]].
- Wait until August, when the script blows up with
[[: 08: value too great for base (error token is "08")
- Learn about octal in Bash, smack forehead, and curse language designers who thought it was a good idea to make numbers ambiguous in order to save one character instead of using something reasonable like a
0oprefix to fit with the already ubiquitous
At no point did anyone profit during this exchange.
As an aside, this is the sort of thing that only exhaustive testing will catch, because “01” through “07” are the same value whether decoded as octal or decimal, and “10” through “12” are decoded as decimal. Only “08” and “09” are actually problematic values.