Created
May 5, 2022 15:44
-
-
Save alanhogan/3c10248254da57b4530e32feefcb5f47 to your computer and use it in GitHub Desktop.
Fail on pattern match of output while showing output. zsh + macOS compatible
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
# Allow failing on regex pattern match | |
# See https://superuser.com/a/1717757/60337 | |
failon() ( | |
pattern="$1" | |
shift | |
[ "$#" -eq 0 ] && set cat | |
FAILON_STATUS="${FAILON_STATUS:-125}" | |
set -o pipefail | |
{ "$@" \ | |
| "$@" >&3 \ | |
| { grep -q -- "$pattern" && return "$FAILON_STATUS" || return 0; } | |
} 3>&1 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment