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

标签 shell unix process substitution

我正在尝试使用 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/

相关文章:

shell - 如何在shell中获取测试命令返回码?

linux - 使用 Gnome-Schedule 运行打开 Chromium 浏览器的 shell 脚本

bash - 在 UNIX shell 中实现 `sumproduct`

c++ - 有没有办法让我的 win32 程序知道它启动的子进程已经崩溃(而不仅仅是退出)?

java - 使用进程构建器执行两个命令

c# - 在生产网络服务器上执行流程

linux - 如何在 Linux 中将相同的 header 数据附加到一个 header

unix - Cron 作业未启动

linux - 使用 Unix 排序对多个键进行排序——错误?

bash - 带通配符的猫