Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created January 27, 2012 18:44
Show Gist options
  • Save hgdeoro/1690248 to your computer and use it in GitHub Desktop.
Save hgdeoro/1690248 to your computer and use it in GitHub Desktop.
Checks the exit status of piped commands (for old versions of bash)
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