help-bash
[Top][All Lists]
Advanced

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

About using COPROC


From: Peng Yu
Subject: About using COPROC
Date: Fri, 2 Apr 2021 16:01:42 -0500

The following script correctly prints 1 2 3.

coproc {
seq 3
}
exec 3>&"${COPROC[0]}"
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]