shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2309: false positives for non-decimal number

Open BenSYZ opened this issue 8 months ago • 0 comments

Hi, guys! I found bash could support non-decimal number, while shellcheck treats them to be warning.

example code:

if [[ 0x1 -le 0x2 ]];then
    echo true
else
    echo false
fi

from man pages of bash:

       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.

so number (16) could be:

  • 0x10: (hexadecimal base)
  • 020: (octal base)
  • 13#13 (any base)
  • ...

BenSYZ avatar Apr 14 '25 07:04 BenSYZ