Last active
October 4, 2021 03:59
-
-
Save adoyle-h/4cfc93760d1cddf41db9e3bf4f401dc8 to your computer and use it in GitHub Desktop.
"shopt -s inherit_errexit" is important
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
#!/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 |
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
#!/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:未找到命令 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you inverted the results . correct it