Skip to content

Instantly share code, notes, and snippets.

@jpf
Created May 6, 2009 00:20
Show Gist options
  • Save jpf/107298 to your computer and use it in GitHub Desktop.
Save jpf/107298 to your computer and use it in GitHub Desktop.
#!/bin/bash
# How to exit if any command in a bash subshell fails.
exitIfFailed ()
{
rv=$?;
if [ $rv -ne 0 ]; then
exit $rv;
fi
}
(
echo -n "T";
# false;
exitIfFailed;
echo -n "e";
# false;
exitIfFailed;
echo -n "s";
# false;
exitIfFailed;
echo -n "t";
# false;
exitIfFailed;
) # > /dev/null 2>&1
subshell_rv=$?
echo ""
echo "Returned: $subshell_rv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment