help-bash
[Top][All Lists]
Advanced

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

Re: About using COPROC


From: Reuti
Subject: Re: About using COPROC
Date: Fri, 2 Apr 2021 23:16:01 +0200

> 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]}"

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
> 




reply via email to

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