Skip to main content
A Bash numeric base literal is a syntactic construct used within arithmetic evaluation contexts to define an integer in an arbitrary radix (base) ranging from 2 to 64.

Syntax

The primary syntax for defining a base literal utilizes the hash (#) delimiter:
  • base: A decimal integer between 2 and 64 specifying the radix.
  • number: The sequence of characters representing the integer value in the specified radix.
If the base# prefix is omitted entirely, Bash evaluates the number as a standard base 10 integer (unless a C-style prefix is present). The # delimiter is strictly a separator and cannot be used without a preceding base.

Lexical Representation and Character Mapping

To represent digit values greater than 9, Bash employs a specific character mapping sequence:
  • Values 0–9: Digits 0 through 9.
  • Values 10–35: Lowercase letters a through z.
  • Values 36–61: Uppercase letters A through Z.
  • Value 62: The at-symbol @.
  • Value 63: The underscore _.
Note: If the specified base is less than or equal to 36, Bash treats lowercase and uppercase letters interchangeably for values 10 through 35.

C-Style Base Prefixes

In addition to the base#number format, Bash supports standard C-style prefixes for octal and hexadecimal literals:
  • Octal (Base 8): A leading 0 (zero) followed by octal digits.
  • Hexadecimal (Base 16): A leading 0x or 0X followed by hexadecimal digits.

Arithmetic Evaluation Contexts

Bash evaluates numeric base literals in all arithmetic evaluation contexts. These contexts include:
  • Arithmetic expansions ($(( ... )))
  • Arithmetic compound commands ((( ... )))
  • The let builtin command
  • Array subscripts (array[index])
  • Parameter substring expansion offsets and lengths (${parameter:offset:length})
  • Integer-attributed variable assignments (variables declared with declare -i)
  • Conditional command arithmetic operators (e.g., -eq, -lt) evaluated strictly within the [[ ... ]] keyword.
Note: The [ (test) builtin command is not an arithmetic evaluation context. It relies on standard C-library string-to-integer conversion. Using a Bash base literal inside [ (e.g., [ 16#FF -eq 255 ]) will result in an integer expression expected error.

Syntax Visualization

Tired of Poor Bash Skills? Fix That With Deep Grasping!Learn More