开发者

Using -0 with xargs

开发者 https://www.devze.com 2023-04-05 06:33 出处:网络
I am trying to give an input to xargs that is NUL separated. To this eff开发者_StackOverflow中文版ect I have this:

I am trying to give an input to xargs that is NUL separated. To this eff开发者_StackOverflow中文版ect I have this:

$ echo -n abc$'\000'def$'\000' | xargs -0 -L 1

I get

abcdef

I wonder why doesn't it print o/p as

abc
def


Your main problem is that you forgot -e:

$ echo -n abc$'\000'def$'\000' |cat -v
abcdef

No zero bytes are seen. But this:

$ echo -en abc'\000'def'\000' |cat -v
abc^@def^@

is more like it, the ^@ is how cat -v shows a zero byte. And now for xargs:

$ echo -en abc'\000'def'\000' | xargs -0 -L 1
abc
def

Try help echo from your bash prompt.


Try treating the input as a single quoted string.

echo -ne "abc\0def\0" | xargs -0 -L 1
0

精彩评论

暂无评论...
验证码 换一张
取 消