I stuck with an strange behaviour of readarray
command.
The man bash
states:
readarray
Read lines from the standard input into the indexed array variable array
but these scripts don't work (array is empty):
unset arr; (echo a; echo b; echo c) | readarray arr; echo ${#arr[@]}
unset arr; cat /etc/passwd | readarray arr; echo ${#arr[@]}
And these work:
unset arr; readarray arr < /etc/passwd ; echo ${#arr[@]}
unset arr; mkfifo /tmp/fifo; (echo a; echo b; echo c) > /tmp/fifo & mapfile arr < /tmp/fifo ; echo ${#arr[@]}
What wrong with pipe?
readarray
isn't that important). – ilkkachu Feb 21 '22 at 12:54