Created
January 27, 2012 18:44
-
-
Save hgdeoro/1690248 to your computer and use it in GitHub Desktop.
Checks the exit status of piped commands (for old versions of bash)
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
function check_pipstatus () { | |
PSTATUS=( "${PIPESTATUS[@]}" ) # copiamos array | |
if [ -z "$PSTATUS" ] ; then | |
echo "ERROR: PIPESTATUS no fue pasado por parametro" | |
exit 1 | |
fi | |
if [ ${#PSTATUS[@]} -lt 2 ] ; then | |
echo "ERROR: PIPESTATUS posee menos de 2 elementos" | |
exit 1 | |
fi | |
for exit_status in ${PSTATUS[@]} ; do | |
if [ $exit_status -ne 0 ] ; then | |
echo "ERROR: uno de los elementos de PIPESTATUS es distinto a 0: $exit_status" | |
exit 1 | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment