bash allows $'string' expansion. My man bash says:
Words of the form
$'string'are treated specially. The word expands tostring, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:
\aalert (bell)
\bbackspace
\e
\Ean escape character
\fform feed
\nnew line
\rcarriage return
\thorizontal tab
\vvertical tab
\backslash
\'single quote
\"double quote
\nnnthe eight-bit character whose value is the octal valuennn(one to three digits)
\xHHthe eight-bit character whose value is the hexadecimal valueHH(one or two hex digits)
\cxa control-xcharacterThe expanded result is single-quoted, as if the dollar sign had not been present.
But why does bash not convert $'\0' and $'\x0' into a null character?
Is it documented? Is there a reason? (Is it a feature or a limitation or even a bug?)
$ hexdump -c <<< _$'\0'$'\x1\x2\x3\x4_'
0000000 _ 001 002 003 004 _ \n
0000007
echo gives the expected result:
> hexdump -c < <( echo -e '_\x0\x1\x2\x3_' )
0000000 _ \0 001 002 003 _ \n
0000007
My bash version
$ bash --version | head -n 1
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Why echo $'foo\0bar' does not behave as echo -e 'foo\0bar'?