Last active
January 6, 2017 03:12
-
-
Save umegaya/4b71ac5fe70bb99e57e2ce16192ad26f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
- highlight | |
- add set -e bofore subshell | |
- when you receive output of subshell, do not use local val=$(sub shell), but use local val; val=$(sub shell). | |
- test.sh | |
``` | |
#!/bin/bash | |
set -e errexit | |
set -o pipefail | |
cwd=`dirname $0` | |
source $cwd/testsrc.sh | |
digest=$(set -e; testfunc) # use set -e to abort | |
echo "digest=[$digest]" | |
``` | |
- testsrc.sh | |
``` | |
#!/bin/bash | |
function subtestfunc() { | |
exit 1; | |
} | |
function testfunc() { | |
local ret # do not directly capture output of subshell | |
ret=$(set -e; subtestfunc) | |
local ec=$? | |
echo "ec=[$ec],ret=[$ret]" | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment