It seems like bash, and also dash, filter out any ASCII NUL from my scripts.
$ printf 'test="\000a" ; echo ${#test}' | sh
1
$ printf 'test="\001a" ; echo ${#test}' | sh
2
$ printf 'ec\000ho test' | sh
test
$ # (Same for bash)
While I agree that using NUL is a bad bad idea (for example argument passing to programs works with NUL-terminated strings), I don't see where this behaviour is sanctioned by the POSIX standard.
It gets even worse when this behaviour is deciding on the syntactical correctness of the file.
$ printf 'echo "\\\000"' | sh
sh: Syntax error: Unterminated quoted string
$ printf 'echo "\\\000"' | bash
bash: line 1: unexpected EOF while looking for matching `"'
bash: line 2: syntax error: unexpected end of file
$ printf 'echo "\\\134"' | sh
\
What essential part did I miss, or is the NUL-removal only a decision on how to cope with unspecified behaviour?