]> git.tuebingen.mpg.de Git - gsu.git/commitdiff
config: Declare local config variables earlier.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Apr 2017 13:27:54 +0000 (15:27 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Apr 2017 14:03:20 +0000 (16:03 +0200)
In gsu_check_options() we declare the six option variables (name,
option_type, ...)  local to avoid overwriting the content of
user-defined variables of the same name.

Of course this only works if the variables are declared local before
we assign to them. This is currently not the case because the

eval "${gsu_options[$i]}"

statement in the first loop sets these variables before they are
declared in the body of the second loop.

This bug is benign since gsu_check_options() is usually called before
any command handler is executed. Let's fix it anyway.

config

diff --git a/config b/config
index 4e731afd84e344b5eee6ef61c7f26b345ca5a754..6b3be62f0eceabdf5551accfeddb3a9f3f690f6d 100644 (file)
--- a/config
+++ b/config
@@ -6,7 +6,8 @@
 # file.
 gsu_check_options()
 {
-       local i conf="${gsu_config_file:=${HOME:-}/.$gsu_name.rc}" val
+       local i conf="${gsu_config_file:=${HOME:-}/.$gsu_name.rc}" val orig_val
+       local name option_type default_value required description help_text
 
        for ((i=0; i < ${#gsu_options[@]}; i++)); do
                eval "${gsu_options[$i]}"
@@ -17,9 +18,12 @@ gsu_check_options()
        [[ -r "$conf" ]] && source "$conf"
 
        for ((i=0; i < ${#gsu_options[@]}; i++)); do
-               local name= option_type= default_value= required=
-               local description= help_text=
-               local val orig_val
+               name=
+               option_type=
+               default_value=
+               required=
+               description=
+               help_text=
 
                eval "${gsu_options[$i]}"