From 23d7a0005d6f7c17825473b50bd04bf89181aaa1 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Mar 2019 16:05:32 +0100 Subject: [PATCH 1/3] Escape $ in getopts --- data/helpers.d/getopts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/helpers.d/getopts b/data/helpers.d/getopts index 7055325f1..891fdaaeb 100644 --- a/data/helpers.d/getopts +++ b/data/helpers.d/getopts @@ -152,6 +152,8 @@ ynh_handle_getopts_args () { fi # Escape double quote to prevent any interpretation during the eval all_args[$i]="${all_args[$i]//\"/\\\"}" + # Escape $ as well to prevent the string following it to be seen as a variable. + all_args[$i]="${all_args[$i]//$/\\\$}" eval ${option_var}+=\"${all_args[$i]}\" shift_value=$(( shift_value + 1 )) @@ -193,6 +195,8 @@ ynh_handle_getopts_args () { # Escape double quote to prevent any interpretation during the eval arguments[$i]="${arguments[$i]//\"/\\\"}" + # Escape $ as well to prevent the string following it to be seen as a variable. + all_args[$i]="${all_args[$i]//$/\\\$}" # Store each value given as argument in the corresponding variable # The values will be stored in the same order than $args_array From ad748a75f62490386c7ca97b92191d3ee2d3fa0d Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Mar 2019 16:15:54 +0100 Subject: [PATCH 2/3] eval is useful and working before being evil... --- data/helpers.d/getopts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/data/helpers.d/getopts b/data/helpers.d/getopts index 891fdaaeb..90db671c4 100644 --- a/data/helpers.d/getopts +++ b/data/helpers.d/getopts @@ -155,6 +155,13 @@ ynh_handle_getopts_args () { # Escape $ as well to prevent the string following it to be seen as a variable. all_args[$i]="${all_args[$i]//$/\\\$}" + # For the record. + # We're using eval here to get the content of the variable stored itself as simple text in $option_var... + # Other ways to get that content would be to use either ${!option_var} or declare -g ${option_var} + # But... ${!option_var} can't be used as left part of an assignation. + # declare -g ${option_var} will create a local variable (despite -g !) and will not be available for the helper itself. + # So... Stop fucking arguing each time that eval is evil... Go find an other working solution if you can find one! + eval ${option_var}+=\"${all_args[$i]}\" shift_value=$(( shift_value + 1 )) fi From 652edc204cbf9fbcd7fc9d273d429dc05a0eef7f Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 16 Mar 2019 16:53:07 +0100 Subject: [PATCH 3/3] Syntax fix --- data/helpers.d/getopts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/helpers.d/getopts b/data/helpers.d/getopts index 90db671c4..70d4a13d3 100644 --- a/data/helpers.d/getopts +++ b/data/helpers.d/getopts @@ -203,7 +203,7 @@ ynh_handle_getopts_args () { # Escape double quote to prevent any interpretation during the eval arguments[$i]="${arguments[$i]//\"/\\\"}" # Escape $ as well to prevent the string following it to be seen as a variable. - all_args[$i]="${all_args[$i]//$/\\\$}" + arguments[$i]="${arguments[$i]//$/\\\$}" # Store each value given as argument in the corresponding variable # The values will be stored in the same order than $args_array