![Bash 스크립트에 오류 처리기를 연결하는 방법이 있습니까?](https://linux55.com/image/108320/Bash%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EC%97%90%20%EC%98%A4%EB%A5%98%20%EC%B2%98%EB%A6%AC%EA%B8%B0%EB%A5%BC%20%EC%97%B0%EA%B2%B0%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%B4%20%EC%9E%88%EC%8A%B5%EB%8B%88%EA%B9%8C%3F.png)
스크립트의 특정 명령이 실패할 경우 실행될 오류 처리기를 bash에 추가하는 방법이 있습니까?
알아요 set -o errexit
. 하지만 이 방법으로는 사용자 정의 오류 처리기를 추가할 수 없습니다.
답변1
set -e
trap "do your custom stuff here" EXIT
...
# now whenever there's an error condition, due to the set -e, the script will exit
# and upon this exit, the trap custom message shall be activated.