将 -0 与 xargs 一起使用

发布于 2024-12-05 05:05:04 字数 219 浏览 3 评论 0原文

我正在尝试向 xargs 提供以 NUL 分隔的输入。为此,我有这样的:

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

我想

abcdef

知道为什么它不将 o/p 打印为

abc
def

I am trying to give an input to xargs that is NUL separated. To this effect I have this:

$ echo -n abc

I get

abcdef

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

abc
def
\000'def

I get


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


\000' | xargs -0 -L 1

I get

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

围归者 2024-12-12 05:05:04

您的主要问题是您忘记了 -e

$ echo -n abc

看不到零字节。但这:

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

更像是, ^@cat -v 显示零字节的方式。现在对于 xargs

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

在 bash 提示符下尝试 help echo

\000'def

看不到零字节。但这:


更像是, ^@cat -v 显示零字节的方式。现在对于 xargs


在 bash 提示符下尝试 help echo

\000' |cat -v abcdef

看不到零字节。但这:

更像是, ^@cat -v 显示零字节的方式。现在对于 xargs

在 bash 提示符下尝试 help echo

Your main problem is that you forgot -e:

$ echo -n abc

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.

\000'def

No zero bytes are seen. But this:


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


Try help echo from your bash prompt.

\000' |cat -v abcdef

No zero bytes are seen. But this:

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

Try help echo from your bash prompt.

屌丝范 2024-12-12 05:05:04

尝试将输入视为单引号字符串。

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

Try treating the input as a single quoted string.

echo -ne "abc\0def\0" | xargs -0 -L 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文