![stdall.log, stderr.log 및 stdoutput.log로 출력 리디렉션 + 상태 코드 반환](https://linux55.com/image/104444/stdall.log%2C%20stderr.log%20%EB%B0%8F%20stdoutput.log%EB%A1%9C%20%EC%B6%9C%EB%A0%A5%20%EB%A6%AC%EB%94%94%EB%A0%89%EC%85%98%20%2B%20%EC%83%81%ED%83%9C%20%EC%BD%94%EB%93%9C%20%EB%B0%98%ED%99%98.png)
검색해서 해결방법을 찾았습니다여기,하지만반환 상태 코드부분.
보시다시피 서브셸을 사용하고 거기에서 상태 코드를 가져올 수 없으므로 이 답변을 기반으로 다음과 같이 작성하고 싶습니다.
(((cmd; status=$?) | tee stdout.log) 3>&1 1>&2 2>&3 | tee stderr.log) &> all.log
if [ $status -ne 0 ]
then
# do something with stderr.log and stdall.log
fi
물론 내 예에서는 $status
상위 셸에 표시되지 않습니다. 필요에 맞게 어떻게 수정할 수 있나요?