Skip to content

Instantly share code, notes, and snippets.

@stevekuznetsov
Last active May 9, 2016 15:12
Show Gist options
  • Save stevekuznetsov/a64e124ea65bb085a97afe706dc55a85 to your computer and use it in GitHub Desktop.
Save stevekuznetsov/a64e124ea65bb085a97afe706dc55a85 to your computer and use it in GitHub Desktop.
readonly source failures
#!/bin/bash
function init() {
source readonly.sh
echo "inside init: ${MY_VAR[*]}" # success
}
init
echo "after init: ${MY_VAR[*]}" # failure
$ test.sh
inside init: some-text
init.sh: line 9: MY_VAR[*]: unbound variable
#!/bin/bash
readonly MY_VAR=(
"some-text"
)
#!/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