Skip to content

Instantly share code, notes, and snippets.

@umegaya
Last active January 6, 2017 03:12
Show Gist options
  • Save umegaya/4b71ac5fe70bb99e57e2ce16192ad26f to your computer and use it in GitHub Desktop.
Save umegaya/4b71ac5fe70bb99e57e2ce16192ad26f to your computer and use it in GitHub Desktop.
- 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