Skip to content

Instantly share code, notes, and snippets.

@eksperimental
Created December 22, 2021 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eksperimental/fcbed16e9011e66f9ed631980219326d to your computer and use it in GitHub Desktop.
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.
#!/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