gpt4 book ai didi

shell - Bourne Shell 中是否有像 Bash 中那样的进程替换?

转载 作者:行者123 更新时间:2023-12-01 09:33:48 25 4
gpt4 key购买 nike

我正在尝试使用 cmp 来比较两个命令(Bourne shell)的输出:

cmp <(ls $file1) <(ls $file2)

它在 Bash 中运行良好,但在 Bourne 中无法运行。有什么解决办法吗?非常感谢!

最佳答案

进程替换是(或曾经)使用命名管道实现的。您可以使用 mkfifo直接重新创建相同的行为:

mkfifo pipe1 pipe2
ls $file1 > pipe1 &
ls $file2 > pipe2 &
cmp pipe1 pipe2
rm pipe1 pipe2

但是除了性能之外,与考虑常规文件相比,您不会获得太多 yield ......

关于shell - Bourne Shell 中是否有像 Bash 中那样的进程替换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39812507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com