안녕하세요. shell 을 배운지 얼마 안된 초짜 입니다.
현재 learning the bash shell 책을 보고 있습니다.
shell variable중 $! 는 "A related built-in shell variable is $!, which contains the process ID of the most recently invoked background job"이라고 설명 되어 있습니다.
shell에서 1개의 명령어를 background로 돌렸을 경우 echo $! 했을 때 올바르게 값이 나옵니다만,
2개의 명령어를 pipe로 연결 했을 때,
i.e) cat a.txt | less &
위와 같이 명령어를 실행하고 $!를 출력했을 때, less pid가 출력됩니다.