[ "$((hex_string_1))" -eq "$((hex_string_2))" ]
With older versions of
dash, you needed:
[ "$(($hex_string_1))" -eq "$(($hex_string_2))" ]
[ "$hex_string_1" -eq "$hex_string_2" ]
The POSIX specification for the
test utility says operands have to be integers, without specifying which forms of integers (decimal, octal, hexadecimal...) are to be supported, but that's actually covered in point 6 at the Utility Argument Syntax which states what the default would be when not specified:
6. Unless otherwise specified, whenever an operand or option-argument is, or contains, a numeric value:
- The number is interpreted as a decimal integer.
- Numerals in the range 0 to 2147483647 are syntactically recognized as numeric values.
- When the utility description states that it accepts negative numbers as operands or option-arguments, numerals in the range -2147483647 to 2147483647 are syntactically recognized as numeric values.
- Ranges greater than those listed here are allowed.
[ 0x10 -eq 16 ] only works with
[ 0x1 -eq 0x01] works in AT&T
ksh (but only because they're treated as
[ 0x2 -eq 0x123 ] would return true as well), and except for
posh (where's that a bug), all
[ implementations return false on
[ 010 -eq 8 ] (as in
010 is treated as decimal, not octal)).
ksh93, while you can't do
[ 0x10 -eq 16 ], you can do
[ +0x10 -eq 16 ] (also with
posh). In both AT&T
pdksh derivatives (including
posh), you can also do
[ '16#10' -eq 16 ].