Skip to content

Instantly share code, notes, and snippets.

@adoyle-h adoyle-h/a.bash
Created Jun 28, 2019

Embed
What would you like to do?
"shopt -s inherit_errexit" is important
#!/usr/bin/env bash
set -o errexit
set -o nounset
f() {
echo -n hello
INVALID_COMMAND
echo -n world
}
bar=$(f)
echo "bar is $bar"
# It will print
# /10:行9: INVALID_COMMAND:未找到命令
#!/usr/bin/env bash
set -o errexit
set -o nounset
shopt -s inherit_errexit
f() {
echo -n hello
INVALID_COMMAND
echo -n world
}
bar=$(f)
echo "bar is $bar"
# It will print
# ./10:行9: INVALID_COMMAND:未找到命令
# bar is helloworld
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.