Interview Prep/Shell Scripting/Troubleshooting: quoting, expansion and tool-input bugs

A report script fails only at 08:00 and 09:00 with `bash: 08: value too great for base (error token is "08")`.

IntermediateTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer

Likely causes → hour=$(date +%H) gives 08 and 09, and Bash arithmetic treats a leading zero as octal, where 8 and 9 are invalid. At 00–07 it silently works, which is why it went unnoticed.

Diagnose → bash -c 'h=08; echo $((h + 1))' reproduces it.

Fix → Force base 10: $(( 10#$hour + 1 )), or ask for an unpadded value (date +%-H with GNU date).

Prevent → Use 10# whenever doing arithmetic on dates, months or zero-padded IDs; test with edge values.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: quoting, expansion and tool-input bugs