COPROC: mudanças entre as edições

De Wiki Clusterlab.com.br
Ir para navegação Ir para pesquisar
Sem resumo de edição
Linha 4: Linha 4:
Run a "bc" in a subshell and keep it running to call multiple times from a loop without the overhead to instantiate "bc" every single iteration.
Run a "bc" in a subshell and keep it running to call multiple times from a loop without the overhead to instantiate "bc" every single iteration.
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
coproc bc
coproc stdbuf -o0 sed 's/.*/msg: &/'
for i in {1..10}
for i in {1..10}
do  
do  
   echo $i'*'$i >&${COPROC[1]}
   echo $i >&${COPROC[1]}
   read -u ${COPROC[0]} rc
   read -u ${COPROC[0]} rc
   echo $rc
   echo $rc

Edição das 11h43min de 4 de dezembro de 2019

Articles

Example

Run a "bc" in a subshell and keep it running to call multiple times from a loop without the overhead to instantiate "bc" every single iteration.

coproc stdbuf -o0 sed 's/.*/msg: &/'
for i in {1..10}
do 
  echo $i >&${COPROC[1]}
  read -u ${COPROC[0]} rc
  echo $rc
done
kill $COPROC_PID

OUTPUT

1
4
9
16
25
36
49
64
81
100