Last active
February 14, 2022 21:42
-
-
Save josepsmartinez/96787d367fe888b5075f0ba23c83c7a3 to your computer and use it in GitHub Desktop.
Bash practices for handling exit codes (Reference: https://stackoverflow.com/a/45817972/4449273)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# In case of simple logging | |
complex_command && echo "Success" >> log.txt || echo "Failure" >> log.txt | |
# In case of complex command chaining | |
complex_command | |
if [ $? -ne 0]; then | |
success_complex_command # this command could fail as well | |
# its exit code can be treated in a nested manner by testing $? again | |
else | |
failure_complex_command | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment