Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 43 |
Nodes: | 6 (0 / 6) |
Uptime: | 108:38:54 |
Calls: | 290 |
Files: | 905 |
Messages: | 76,698 |
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.)
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?
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"
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"
On 20.10.2024 00:56, Kenny McCormack wrote:
In article <vf1942$1uso$1@dont-email.me>,
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
On Sat, 19 Oct 2024 14:52:01 +0200, Janis Papanagnou wrote:
Also, if above code is how to use co-processes in Bash, I consider that >>>> extremely clumsy (if compared to, say, Ksh).
"extremely" seems more than a bit over the top. Maybe somewhat clumsy, but >> hardly "extremely".
I don't think it makes much sense to discuss subjective valuations.
But okay.
Mine stems from a "per-feature level" (and is no absolute). It was
based on LDO's suggestion (which was a bit more complex than your
version) that used; (1) a [new] keyword, (2) command grouping (not
sure it's necessary[*] in the first place?), (3) using an explicit
descriptor through (4) a variable, (5) using an array instead of a
scalar element, and (6) using 'wait' (I'm also not sure this is
necessary in the first place or just the poster not knowing better?).
For a simple feature that's really a lot compared to e.g. ksh's way.
(YMMV. But if "somewhat clumsy" triggers less emotions then I'm fine
with that.)
(Yes, '|' is different than '|&', which is more like '&' since it
separates commands where the pipe connects them. But that was not
the point here.)
I meant that you can have several asynchroneous processes started which
are each connected to the same main shell session with pipes for communicating. For that you have to redirect the default pipe channels because there's of course just one option '-p' with the commands 'read'
and 'print' and you need some way to differentiate the various channels.
In article <vf239t$9ikn$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
I don't think it makes much sense to discuss subjective valuations.
But okay.
It has to do with certain habits/conventions that Usenet posters have
fallen into. [...]
[...]
No comment on the rest, other than to say that you seem to claim that ksh does support multiple concurrent coprocs, which I think is wrong, [...]
On Fri, 25 Oct 2024 06:26:14 +0200, Janis Papanagnou wrote:
I meant that you can have several asynchroneous processes started which
are each connected to the same main shell session with pipes for
communicating. For that you have to redirect the default pipe channels
because there's of course just one option '-p' with the commands 'read'
and 'print' and you need some way to differentiate the various channels.
Bash does that in a nicer way.
No comment on the rest, other than to say that you seem to claim that ksh
does support multiple concurrent coprocs, which I think is wrong, [...]
I meant that you can have several asynchroneous processes started
which are each connected to the same main shell session with pipes
for communicating. For that you have to redirect the default pipe
channels because there's of course just one option '-p' with the
commands 'read' and 'print' and you need some way to differentiate
the various channels. I just hacked a sample to show what I mean...
On Fri, 25 Oct 2024 06:26:14 +0200, Janis Papanagnou wrote:
I meant that you can have several asynchroneous processes started which
are each connected to the same main shell session with pipes for
communicating. For that you have to redirect the default pipe channels
because there's of course just one option '-p' with the commands 'read'
and 'print' and you need some way to differentiate the various channels.
Bash does that in a nicer way.