bash: How do I ensure termination of process substitution used with exec?

前端 未结 5 864
时光说笑
时光说笑 2021-01-06 08:48

If I run

$#/bin/bash
for i in `seq 5`; do
    exec 3> >(sed -e \"s/^/$i: /\"; echo \"$i-\")
    echo foo >&3
    echo bar >&3
    exec 3&         


        
5条回答
  •  失恋的感觉
    2021-01-06 09:20

    The "obvious" answer is to get rid of the process substitution.

    for i in `seq 5`; do
        echo foo | sed -e "s/^/$i: /"; echo "$i-"
        echo bar | sed -e "s/^/$i: /"; echo "$i-"
    done
    

    So the question becomes, do you really need to structure your code using process substitution? The above is much simpler than trying to synchronize an asynchronous construct.

提交回复
热议问题