小编cjf*_*jfp的帖子

如何显示NUL分隔数据的中间管道结果?

如何组合以下两个命令:

find . -print0 | grep -z pattern | tr '\0' '\n'
find . -print0 | grep -z pattern | xargs -0 my_command
Run Code Online (Sandbox Code Playgroud)

进入单一管道?如果我不需要NUL分隔符,那么我可以这样做:

find . | grep pattern | tee /dev/tty | xargs my_command
Run Code Online (Sandbox Code Playgroud)

我想避免使用这样的临时文件:

find . -print0 | grep -z pattern > tempfile
cat tempfile | tr '\0' '\n'
cat tempfile | xargs -0 my_command
rm tempfile
Run Code Online (Sandbox Code Playgroud)

这个问题是对这些答案的后续跟进:

1)使用/ dev/tty显示中间管道结果:

https://unix.stackexchange.com/a/178754/8207082

2)使用NUL分隔的文件列表:

/sf/answers/10022071/

编辑使用my_command而不是command.

后续问题:

在子shell中写入/ dev/tty的Makefile规则?

bash sh

3
推荐指数
1
解决办法
158
查看次数

标签 统计

bash ×1

sh ×1