【发布时间】:2016-12-12 06:45:50
【问题描述】:
<(commands ...) 在 bash/zsh 中将输出行为作为文件。
是否存在 POSIX 等价物?
【问题讨论】:
-
@PP,我不太喜欢那个特定的潜在欺骗,因为它包含一些误解(其中,bash 3.x 不支持进程替换;这是一个 msys 限制,而不是基于版本的限制)。
标签: bash posix sh zsh process-substitution
<(commands ...) 在 bash/zsh 中将输出行为作为文件。
是否存在 POSIX 等价物?
【问题讨论】:
标签: bash posix sh zsh process-substitution
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 @ 是原子的)等。实际上,这就是 <( ... ) 在幕后所做的一切:它只是这个答案的更强大变体的语法糖。
<( ... ) 在幕后所做的在/dev/fd 不可用的平台上;它使用pipe(2) 匿名描述符对。
mktemp。要么需要重新实现mktemp,只使用 POSIX shell 行为,要么必须想出一些技巧。