Can \0
be used on the command line?
Background
For testing corner cases in GNU Parallel I was curious whether all characters were correctly quoted on the command line. Most of them are:
perl -e 'print pack ("c*",1..255,10)' | parallel -k echo | md5sum
d03484ca75b3e38be411198d66bf4611 -
perl -e 'print pack ("c*",1..255,10)' | md5sum
d03484ca75b3e38be411198d66bf4611 -
But \0
seems to be tricky (here illustrated with A\0B\n
):
perl -e 'print pack ("c*",65,0,66,10)' | wc -c
4 (A\0B\n)
perl -e 'print pack ("c*",65,0,66,10)' | parallel echo | wc -c
2 (A\n)
perl -e 'print pack ("c*",65,0,66,10)' | parallel --dry-run echo | wc -c
9 (echo A\0B\n)
perl -e 'print "echo ",pack ("c*",65,0,66,10)' | bash | wc -c
3 (AB\n)
I can sort of justify the second example: \0
may be interpreted as EOS, but then that also ought to be the case in example 4. Example 3 stresses that GNU Parallel does not see \0
as EOS, but passes it on to bash
.
Can you explain what is going on—especially case 4 puzzles me.
And more importantly:
Is there a way to quote \0
on the command line so that e.g. echo
will see it?
bash
decides to skip those NUL bytes. Other shells behave differently. – Stéphane Chazelas Oct 11 '14 at 20:06