help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About using COPROC


From: Peng Yu
Subject: Re: About using COPROC
Date: Fri, 2 Apr 2021 16:39:45 -0500

On Fri, Apr 2, 2021 at 4:16 PM Reuti <reuti@staff.uni-marburg.de> wrote:
>
>
> > Am 02.04.2021 um 23:01 schrieb Peng Yu <pengyu.ut@gmail.com>:
> >
> > The following script correctly prints 1 2 3.
> >
> > coproc {
> > seq 3
> > }
> > exec 3>&"${COPROC[0]}"
>
> Besides that it works, shouldn't it be:
>
> exec 3<&"${COPROC[0]}"

That is something I don't understand either. Why `exec 3>&"${COPROC[0]}"` works?

> Looks like both directions are in place.
>
> -- Reuti
>
>
> > sleep 1
> > while IFS=$'\t' read -r -u 3 line; do
> >    builtin printf '%s\n' "$line"
> > done
> >
> > But if I run the following script. I don't quite understand why the
> > following does not work but the previous one works? Could anybody help
> > explain coproc?
> >
> > coproc {
> > seq 3
> > }
> > sleep 1
> > declare -p COPROC
> > while IFS= read -r -u "${COPROC[0]}" line; do
> >    builtin printf '%s\n' "$line"
> > done
> >
> > it prints the following.
> >
> > ./notworking.sh: line 8: declare: COPROC: not found
> > ./notworking.sh: line 9: read: : invalid file descriptor specification
> >
> > --
> > Regards,
> > Peng
> >
>


-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]