More coproc questions

谁说我不能喝 提交于 2019-12-05 13:52:20

I am not sure why your usage of coproc is not working. Your example works for me with bash 4.2.8 on Mac OS X. Maybe certain versions of bash are buggy here.

It sounds like you could redirect from a process substitution instead of using a coprocess.

while read foo bar baz quux; do
    : use foo, bar, baz, quux in various commands
done < <(commands | that | generate --your lines-to-read)

This can be handy when your input is not already in a simple file where you could use plain redirection.


If you want to stick with coproc, you might be able to use an alternate formulation:

coproc { commands | that | generate --your lines-to-read ; }
while read foo bar baz quux; do
    : use foo, bar, baz, quux in various commands
done <&${COPROC[0]}

One of the syntaxes for this is:

while read var1 var2 ... ; do
   # one or more commands
done < file
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!