이것이 bash 매개변수 대체입니까?

이것이 bash 매개변수 대체입니까?

Bash 프로세스 교체를 연구하는 동안 다음을 발견했습니다.

counter=0

while IFS= read -rN1 _; do
    ((counter++))
done < <(find /etc -printf ' ')

echo "$counter files"

내가 올바르게 이해했다면 find 명령의 출력은 "_"를 대체합니다.

하지만:

  • 이것은 어떤 메커니즘인가요?
  • 또한: 무엇을 해야 할까요 read -rN1?

고쳐 쓰다:

추가 질문: 프로세스 대체는 while 루프에서 "완료"를 가리킵니다. 이것이 어떻게 작동하는지, 즉 while 루프가 해당 지점에서 대체를 수행하는 이유입니다. 제가 읽을 수 있는 일반적인 내용이 있나요?

답변1

<(find /etc -printf ' ')이를 "프로세스 대체"라고 합니다. 그것은 생성할 것이다하나' '파일당 문자(공백)입니다. 의 출력은 find /etc -printf ' '파일(또는 파일의 내용)로 제공됩니다. 파일 이름은 명령줄에서 확장됩니다. 이것추가의 <이 파일에서 stdin 리디렉션을 수행합니다.

read -rN1 _(리디렉션된) stdin 에서 이름이 지정된 변수를 _한 번에 한 문자씩 읽고 문자 수를 셉니다(각 문자는 파일을 나타냄).

read다음의 주장은 다음과 같습니다 man bash.

-r     Backslash  does not act as an escape character.  The backslash is considered
       to be part of the line.  In particular, a backslash-newline pair may not  be
       used as a line continuation.

-N nchars
       read returns after reading exactly nchars characters rather than waiting for
       a  complete  line  of  input,  unless  EOF is encountered or read times out.
       Delimiter characters encountered in the input are not treated specially  and
       do not cause read to return until nchars characters are read.

관련 정보