1

It seems readarray blocks and does not return when the input is redirected from a process using <, but it works when input is coming from a pipe |.

This works:

$ (printf "line 1\nline 2\nline 3\n") | (readarray -t ARR ; echo "${ARR[1]}")
line 2

This does not return and needs to be killed

$ readarray -t ARR <(printf "line 1\nline 2\nline 3\n"); echo "${ARR[1]}"

1 Answer 1

3

Process substitution outputs a filename and readarray doesn't read from files. You have to redirect the file into it like:

readarray -t ARR < <(printf "line 1\nline 2\nline 3\n"); echo "${ARR[1]}"

$ echo <(echo hello)
/dev/fd/63
$ cat <(echo hello)
hello
1
  • 1
    What's interesting that it doesn't throw an error for the extra argument the process substitution produces. Neither does it seem to use it, even if it's a valid variable name.
    – ilkkachu
    Mar 23, 2020 at 18:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .