[BASH] 쉘스크립트에서 try catch 와 유사하게 처리하기
Bash에서는 try / catch가 없습니다. 다만 별도로 if 와 exit코드를 통해서 유사하게 구현은 가능합니다. 아래와 같이 if 와 exit로 구현해보겠습니다. #!/bin/bash # Attempt the operation do_something_that_might_fail # Check the exit code if [ $? -ne 0 ]; then # If the operation failed, handle the error echo "An error occurred while doing something." exit 1 fi # If the operation succeeded, continue with the script echo "The operation completed success..
프로그래밍/Server
2023. 3. 8. 10:32