프로세스 입력이 있는 readarray 블록

프로세스 입력이 있는 readarray 블록

프로세스에서 리디렉션 입력을 사용할 때 readarray차단되고 반환되지 않는 것처럼 보이지만 <입력이 파이프에서 나올 때 작동합니다 |.

이것은 작동합니다:

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

이것은 돌아오지 않으며 죽여야 합니다.

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

답변1

프로세스는 출력 파일 이름을 대체하고 readarray는 파일에서 읽지 않습니다. 다음과 같이 파일을 리디렉션해야 합니다.

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

$ echo <(echo hello)
/dev/fd/63
$ cat <(echo hello)
hello

관련 정보