From 76645e8931228a549bab06ace5eba807fe3c818f Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 20 Jun 2022 09:10:40 +0200 Subject: [PATCH] Use export instead of -g declare option. When converting the configuration from the old single value approach to the new array one, the `typeset` and `declare` builtins are used. The problem is that the variables must be used as global variables, so that once the configuration is reloaded, the variable value is used. However, seems that `declare - g` is not a valid builtin on Bash on Mac OSX. Therefore, when the variable is written to the configuration file, an explicit `export` for the variable is written too. This ensures that the variable becomes globally scoped. Also fix a problem of not-evaluated variable. Related to #52 Close #54 --- bin/pgenv | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/pgenv b/bin/pgenv index bd5a81d..06ec738 100755 --- a/bin/pgenv +++ b/bin/pgenv @@ -618,12 +618,14 @@ pgenv_configuration_write_variable(){ echo "# $comment" >> "$file" fi - # if no value supplied, put a comment + if [[ "$name" =~ _OPTIONS$ ]]; then # declare has no way to output a global variable # that is then needed when reloading configuration ! - declare -p "${name}" | sed 's/declare/declare -g /' >> "$file" + declare -p "${name}" >> "$file" + echo "export ${name}" >> "$file" else + # if no value supplied, put a comment if [ -z "$value" ]; then echo -n "#" >> "$file" fi @@ -1209,7 +1211,7 @@ case $1 in fi # warn if no configuration was loaded - if [ ! -z "PGENV_WARNINGS" ]; then + if [ ! -z "$PGENV_WARNINGS" ]; then if [ -z "$PGENV_CONFIGURATION_FILE" ]; then seconds=5 cat <