Created
December 22, 2021 18:29
-
-
Save eksperimental/fcbed16e9011e66f9ed631980219326d to your computer and use it in GitHub Desktop.
Exit with error INMEDIATELY if a script if a warning is generated and matches the given string.
This file contains 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 | |
# Original idea taken from: https://unix.stackexchange.com/questions/556240/how-can-a-command-within-a-pipeline-abort-the-pipeline | |
exit_on_warning() { | |
sed '/atom ::: must be written between quotes, as in :"::", to avoid ambiguity/{q 2}' || kill "$BASHPID" | |
} | |
run() { | |
make docs_elixir | |
echo "Docs successfully generated!" | |
} | |
run 2>&1 | exit_on_warning | cat || cat | |
EXIT_STATUS=${PIPESTATUS[0]} | |
echo "Exit status: ${EXIT_STATUS}" | |
if [ $EXIT_STATUS -eq 0 ]; then | |
exit 0; | |
else | |
exit 1; | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment