Skip to content

Instantly share code, notes, and snippets.

@adoyle-h
Last active October 4, 2021 03:59
Show Gist options
  • Save adoyle-h/4cfc93760d1cddf41db9e3bf4f401dc8 to your computer and use it in GitHub Desktop.
Save adoyle-h/4cfc93760d1cddf41db9e3bf4f401dc8 to your computer and use it in GitHub Desktop.
"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
# ./a.bash:行8: INVALID_COMMAND:未找到命令
# bar is helloworld
#!/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
# ./b.bash:行9: INVALID_COMMAND:未找到命令
@adoyle-h
Copy link
Author

adoyle-h commented Oct 4, 2021

@badrelmers Fixed. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment