별칭 내에서 읽기 루프가 작동하지 않는 동안

별칭 내에서 읽기 루프가 작동하지 않는 동안

Bash에서 다음 명령을 실행하십시오.

echo foo | while read line; do echo $line; done

foo그러나 다음과 같이 출력됩니다 .

alias bar="echo foo | while read line; do echo $line; done"
bar

a \n(또는 공백)를 출력합니다. 이러한 행동 차이의 원인은 무엇입니까?

답변1

변수 확장을 연기하려면 작은따옴표를 사용하세요.

alias bar='echo foo | while read line; do echo $line; done'

관련 정보