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

Andreas Schwab <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <[email protected]>
On Jan 24 2026, Martin D Kealey wrote:

> 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.

The docs say "Integer constants follow the C language definition" and 0x
is not valid C.

> 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.

It's a weak argument, you can always use 0x0$foo if foo can be empty.

-- 
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
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.