Last active
May 9, 2016 15:12
-
-
Save stevekuznetsov/a64e124ea65bb085a97afe706dc55a85 to your computer and use it in GitHub Desktop.
readonly source failures
This file contains 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
#!/bin/bash | |
function init() { | |
source readonly.sh | |
echo "inside init: ${MY_VAR[*]}" # success | |
} | |
init | |
echo "after init: ${MY_VAR[*]}" # failure |
This file contains 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
$ test.sh | |
inside init: some-text | |
init.sh: line 9: MY_VAR[*]: unbound variable |
This file contains 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
#!/bin/bash | |
readonly MY_VAR=( | |
"some-text" | |
) |
This file contains 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
#!/bin/bash | |
set -o nounset | |
set -o errexit | |
set -o pipefail | |
source init.sh | |
echo "after source: ${MY_VAR[*]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment