Skip to content

Commit

Permalink
Remove declare from array definitions.
Browse files Browse the repository at this point in the history
`declare -a` is used for arrays when `declare -p` dumps the
configuration. However when `pgenv_configuration_read` gets back the
configuration, variables becomes locally scoped (see `bash -c "help
declare"). One solution could be to use `declare -g` to make variables
globals, but this does not works on OSX.
Removing `declare -a` (and -x) from arrays seems to make the variable global
even if no `EXPORT` is issued. As a possible compatibility statement,
the `EXPORT` after each variable is left in place.

Close #56
  • Loading branch information
fluca1978 committed Sep 20, 2022
1 parent 2a3412d commit 5366f0c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions bin/pgenv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# VERSION
#
PGENV_VERSION="1.3.1"
PGENV_VERSION="1.3.2"

# https://stackoverflow.com/a/19622569/79202
trap 'exit' ERR
Expand Down Expand Up @@ -620,9 +620,10 @@ pgenv_configuration_write_variable(){


if [[ "$name" =~ _OPTIONS$ ]]; then
# declare has no way to output a global variable
# that is then needed when reloading configuration !
declare -p "${name}" >> "$file"
# using `declare` will make the variable `local`
# once it is read from the pgenv_configuration_read function
# so don't use it and export as a global variable
declare -p "${name}" | sed 's/^declare -ax\? //' >> "$file"
echo "export ${name}" >> "$file"
else
# if no value supplied, put a comment
Expand Down

0 comments on commit 5366f0c

Please sign in to comment.