Artificial intelligent assistant

readarray (or pipe) issue 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?

Maybe try:


unset arr
printf %s\\
a b c | {
readarray arr
echo ${#arr[@]}
}


I expect it will work, but the moment you step out of that last `{` shell `; }` context at the end of the `|`pipeline there you'll lose your variable value. This is because each of the `|`separate `|` processes within a `|`pipeline is executed in a `(`subshell`)`. So your thing doesn't work for the same reason:


( arr=( a b c ) ) ; echo ${arr[@]}


...doesn't - the variable value was set in a _different_ shell process than the one in which you call on it.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 81628ecb60f29ee6a50ab40db0ad3b86