COPROC: mudanças entre as edições
Ir para navegação
Ir para pesquisar
(Criou página com '=Articles= *[https://daemoniolabs.wordpress.com/2011/07/19/entendendo-coprocessos-coproc-do-bash/ Entendendo Coprocessos (coproc) Do Bash]') |
Sem resumo de edição |
||
Linha 1: | Linha 1: | ||
=Articles= | =Articles= | ||
*[https://daemoniolabs.wordpress.com/2011/07/19/entendendo-coprocessos-coproc-do-bash/ Entendendo Coprocessos (coproc) Do Bash] | *[https://daemoniolabs.wordpress.com/2011/07/19/entendendo-coprocessos-coproc-do-bash/ Entendendo Coprocessos (coproc) Do Bash] | ||
=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. | |||
<syntaxhighlight lang=bash> | |||
coproc bc | |||
for i in {1..10} | |||
do | |||
echo $i'*'$i >&${COPROC[1]} | |||
read -u ${COPROC[0]} rc | |||
echo $rc | |||
done | |||
kill $COPROC_PID | |||
</syntaxhighlight> | |||
OUTPUT | |||
<pre> | |||
1 | |||
4 | |||
9 | |||
16 | |||
25 | |||
36 | |||
49 | |||
64 | |||
81 | |||
100 | |||
</pre> |
Edição das 11h29min 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 bc
for i in {1..10}
do
echo $i'*'$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