Merge pull request #1847 from chri2/getopts_echo_printf

Update getopts to accept arguments that are valid arguments to echo
This commit is contained in:
Alexandre Aubin 2024-05-22 13:10:23 +02:00 committed by GitHub
commit 6aa9d05372
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -77,9 +77,9 @@ ynh_handle_getopts_args() {
# And replace long option (value of the option_flag) by the short option, the option_flag itself # And replace long option (value of the option_flag) by the short option, the option_flag itself
# (e.g. for [u]=user, --user will be -u) # (e.g. for [u]=user, --user will be -u)
# Replace long option with = (match the beginning of the argument) # Replace long option with = (match the beginning of the argument)
arguments[arg]="$(echo "${arguments[arg]}" | sed "s/^--${args_array[$option_flag]}/-${option_flag} /")" arguments[arg]="$(printf '%s\n' "${arguments[arg]}" | sed "s/^--${args_array[$option_flag]}/-${option_flag} /")"
# And long option without = (match the whole line) # And long option without = (match the whole line)
arguments[arg]="$(echo "${arguments[arg]}" | sed "s/^--${args_array[$option_flag]%=}$/-${option_flag} /")" arguments[arg]="$(printf '%s\n' "${arguments[arg]}" | sed "s/^--${args_array[$option_flag]%=}$/-${option_flag} /")"
done done
done done