#1106180 dash: printf builtin does not interpret hexadecimal escapes \xNN

Package:
dash
Source:
dash
Description:
POSIX-compliant shell
Submitter:
Daniel Kahn Gillmor
Date:
2025-05-20 20:21:02 UTC
Severity:
normal
#1106180#5
Date:
2025-05-20 17:20:53 UTC
From:
To:
printf appears to typically accept escaped hexadecimal octets of the
form \nXX, where XX are two hexdigits.

out of several printf implementations (including /usr/bin/printf and the
builtins on many other shells), dash alone simply passes those
characters through to output:

```
0 dkg@bob:~$ dash -c "printf '\xd5'" | hd
00000000  5c 78 64 35                                       |\xd5|
00000004
0 dkg@bob:~$ bash -c "printf '\xd5'" | hd
00000000  d5                                                |.|
00000001
0 dkg@bob:~$ posh -c "printf '\xd5'" | hd
00000000  d5                                                |.|
00000001
0 dkg@bob:~$ zsh -c "printf '\xd5'" | hd
00000000  d5                                                |.|
00000001
0 dkg@bob:~$ fish -c "printf '\xd5'" | hd
00000000  d5                                                |.|
00000001
0 dkg@bob:~$ /usr/bin/printf '\xd5' | hd
00000000  d5                                                |.|
00000001
0 dkg@bob:~$
```

https://pubs.opengroup.org/onlinepubs/9799919799/utilities/printf.html

suggests that perhaps \xNN isn't a POSIX standard, so maybe it's within
spec for dash to ignore it.  But it might also be nice to make it work
the way everyone else expects.

#1106180#8
Date:
2025-05-20 18:03:47 UTC
From:
To:
* Daniel Kahn Gillmor <dkg@fifthhorseman.net>, 2025-05-20 13:20:

FWIW, printf is not a builtin in posh:

$ posh -c 'printf --version | head -1'
printf (GNU coreutils) 9.1

#1106180#13
Date:
2025-05-20 19:21:40 UTC
From:
To:
Ah, thanks for that clarification.  At any rate, I can work around what
i was trying to do by using octal escape sequences, which are mandatory
in POSIX shell, and supported by all the printf implementations i've
looked at.  But hex escape sequences are much nicer and very widely
supported, so it would be nice if dash could support them too.