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, 14:54:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vf0dn6$3t9fe$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 19.10.2024 15:35, Kenny McCormack wrote:
In article <vf0a1h$3sn0s$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
On 19.10.2024 13:45, Kenny McCormack wrote:
In article <vec3qb$3q4ms$3@dont-email.me>,
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
On Fri, 11 Oct 2024 22:50:10 +0200, Frank Winkler wrote:
>
... but it still doesn't solve the issue that I need the result to be
visible in the parent shell.
>
coproc { uname -sr; }
read -u ${COPROC[0]} var3
wait $COPROC_PID
echo $var3
>
I'm actually a fan of "coproc" in bash, and I use it in my scripting, but I
think it is overkill in most cases. [...]
>
Also, if above code is how to use co-processes in Bash, I consider
that extremely clumsy (if compared to, say, Ksh).
>
(Mileages may vary, of course.)
I think he was being intentionally verbose for pedagogic purposes.
I won't bore you with the details, but obviously a lot of the text in the
quoted 4 lines is unnecessary in practice.
Just out of curiosity, how would you (Janis) do this in ksh?
For the question on topic I wouldn't (as you wouldn't, IIUC) use
co-processes in the first place - even if [in ksh] we don't need
file descriptor numbers from arrays (like in the bash sample).
I'd use one of the one-liner solutions if I hadn't the "lastpipe"
functionality built-in or available. It also makes no sense, IMO,
to use co-processes that just read a simple value from a command.
Co-processes I have to use only rarely, and the applications are
from commands that provide some "service"; I send a request, and
then I retrieve the response (and rinse repeat, as they say).
The syntax for the [unnecessary] co-process application depicted
above would in Ksh be
uname -sr |&
read -p var
echo "$var"
Janis