On Thu, Jul 17, 2025 at 07:56:39PM -0400, Dan Purgert wrote: > On Jul 18, 2025, lbrtchx@tutamail.com wrote: > > OK, it makes some more sense now. The range of digits in the octal > > system is from 0 to 7, so it would complain with "08" and "09" (but > > not with "10" which would then be "8" in octal), but why would command > > line utilities assume you are encoding numeric values as octal? Now I > > notice many people have stumble on the same problem. There should be a > > straight forward way to encode from "HH:MM:SS" to seconds. I doubt > > that the date utility would assume you are computing numbers as > > octal. > > As I recall, this is a holdover from languages that predate C that an > explicit leading zero indicated octal notation. > > Decimal 7 => 7 > Octal 7 => 07 > Character 7 => '7' Exactly: the leading zero signals octal notation (as a leading 0x would signal hexadecimal). You can override the base with a prefix. It's all in man 1 bash, section "ARITHMETIC EVALUATION": Integer constants follow the C language definition, without suffixes or character constants. Constants with a leading 0 are interpreted as octal numbers. A leading 0x or 0X denotes hexadecimal. Otherwise, numbers take the form [base#]n, where the optional base is a decimal number between 2 and 64 representing the arithmetic base, and n is a number in that base. If base# is omitted, then base 10 is used. When specifying n, if a non-digit is required, the digits greater than 9 are represented by the lowercase letters, the uppercase letters, @, and _, in that order. If base is less than or equal to 36, lowercase and uppercase letters may be used interchangeably to represent numbers between 10 and 35. Cheers -- t
Attachment:
signature.asc
Description: PGP signature