Re: "echo $((0x))" is accepted, treated as 0x0

Martin D Kealey <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAN_U6MXOaPssZOQ2D-Mmvea2a=h3JxiTgREh8QnfBD0iZP4y5g@mail.gmail.com>
On Sat, 24 Jan 2026 at 12:10, Denys Vlasenko <[email protected]> wrote:

> Subject: "echo $((0x))" is accepted, treated as 0x0
> The subject says it all.


Working as intended and as documented.

This is so that "echo $((0x$foo))" works as intended when foo contains only
hexadecimal digits. Note that the empty string complies with that
requirement.

The caveat is, as always, that foo must be a simple hexadecimal numeric
literal, not an arbitrary expression. In particular, not a numeric literal
preceded by a unary minus.

-Martin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.