From 5366f0c2ff55af9b75d6b6ebf087ab3781ea579b Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Tue, 20 Sep 2022 15:44:15 +0200 Subject: [PATCH] Remove `declare` from array definitions. `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 --- bin/pgenv | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/pgenv b/bin/pgenv index 693ab59..8ba88a5 100755 --- a/bin/pgenv +++ b/bin/pgenv @@ -2,7 +2,7 @@ # # VERSION # -PGENV_VERSION="1.3.1" +PGENV_VERSION="1.3.2" # https://stackoverflow.com/a/19622569/79202 trap 'exit' ERR @@ -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