【问题标题】:POSIX shell equivalent to <()POSIX shell 等价于 <()
【发布时间】:2016-12-12 06:45:50
【问题描述】:

&lt;(commands ...) 在 bash/zsh 中将输出行为作为文件。 是否存在 POSIX 等价物?

【问题讨论】:

标签: bash posix sh zsh process-substitution


【解决方案1】:
mkfifo foo.fifo

## if your "commands" is multiple commands
# { commands ...; } >foo.fifo &

# otherwise, if it's just one
commands ... >foo.fifo &

something_else foo.fifo

是最接近的可用等价于

something_else <( commands ... )

【讨论】:

  • 可能的“健壮性”改进将是使用类似mktemp 的东西来为多个管道中的一个安全地生成目录(或者只是为管道生成一个名称,因为@987654324 @ 是原子的)等。实际上,这就是 &lt;( ... ) 在幕后所做的一切:它只是这个答案的更强大变体的语法糖。
  • @mtraceur,这就是&lt;( ... ) 在幕后所做的/dev/fd 不可用的平台上;它使用pipe(2) 匿名描述符对。
  • 对。感谢您的更正 - 我完全忘记了。
  • 没有 POSIX 方法可以做到这一点,因为 POSIX 没有定义 mktemp。要么需要重新实现mktemp,只使用 POSIX shell 行为,要么必须想出一些技巧。
猜你喜欢
  • 1970-01-01
  • 2021-09-23
  • 2016-04-16
  • 2018-05-05
  • 2010-10-01
  • 2023-04-11
  • 2014-04-14
  • 1970-01-01
  • 2012-08-23
相关资源
最近更新 更多