I'll use seq 20 | paste - - - -
as your "pipeline" to generate some lines with 4 words per line.
Here's your problem:
$ seq 20 | paste - - - - | test $number -eq 3 && while read A B C D; do echo "A=$A B=$B C=$C D=$D"; done
^C
The while loop is stuck waiting for input on stdin.
This fix just groups the test and loop together, so read
can access the pipeline's output:
$ seq 20 | paste - - - - | { test $number -eq 3 && while read A B C D; do echo "A=$A B=$B C=$C D=$D"; done; }
A=1 B=2 C=3 D=4
A=5 B=6 C=7 D=8
A=9 B=10 C=11 D=12
A=13 B=14 C=15 D=16
A=17 B=18 C=19 D=20