I understand that the shell process one layer of escaped \ characters for each level of abstraction, and that a command or binary (I also tested /usr/bin/printf) parses another layer of escaped \ characters.

But I don't understand why I could not get any form of either format to work in a shell script, which should work simply by adding an extra \ character for every one present in an output string.

Does anyone know what is going on, or is this an actual bug?

I believe this is a bug in BASH when in SH mode; see post below, or just save yourself the hassle and use the BAS script.

I just ran into the same problem again, and this time I could not refactor the input data to make it decimal.

Unless anyone else can show otherwise, the internal printf in BASH when in SH mode cannot print "\xFF" characters, despite what the man and help pages say. I would say this is a bug, in BASH at least.

#!/bin/sh
printf "\x46\x47"

If you remove the quotes from the string, the shell will escape them away without processing the x part.

What does work then:

#!/bin/sh
PF=`which printf`
$PF "\x46\x47"

So the current solution, if you only have hexadecimalastext, and you want a character or byte, pipe each (text) byte out to a script file (as the second code demonstrates) with \x prepended (before) each value, chmod the script from inside you script, then execute the script on the next line, and remove the script if need be.