Sujet : Re: coproc or whatever in bash and ksh (Was: Different variable assignments)
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shellDate : 19. Oct 2024, 15:11:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vf0en1$3tngr$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 19.10.2024 15:54, Janis Papanagnou wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>
coproc { uname -sr; }
read -u ${COPROC[0]} var3
wait $COPROC_PID
echo $var3
>
The syntax for the [unnecessary] co-process application depicted
above would in Ksh be
uname -sr |&
read -p var
echo "$var"
Concerning the syntax (differences, and generally) I want to add
that it's worthwhile to compare the Ksh syntax with the approach
that we would typically take [in Ksh] to solve the task
uname -sr | read var
echo "$var"
We see that the co-process syntax is a straightforward variant of
the ordinary piping. (As opposed to bash that introduces a lot of
[bulky] stuff that's not even resembling in any way the read-pipe.)
For the interested folks let me hijack my post to add that it's
possible to redirect the co-processes to other file descriptors
(using <&p and >&p with appropriate file descriptor numbers) so
that multiple co-processes can be simultaneously used.
Janis