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.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Syntax
The primary syntax for defining a base literal utilizes the hash (#) delimiter:
base: A decimal integer between2and64specifying the radix.number: The sequence of characters representing the integer value in the specified radix.
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
0through9. - Values 10–35: Lowercase letters
athroughz. - Values 36–61: Uppercase letters
AthroughZ. - Value 62: The at-symbol
@. - Value 63: The underscore
_.
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 thebase#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
0xor0Xfollowed 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
letbuiltin 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.
[ (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
Master Bash with Deep Grasping Methodology!Learn More





