Use 'exec' instead of 'eval', thanks to sergiodj

This commit is contained in:
Samuel Henrique 2024-06-29 12:54:33 +01:00
parent 2deb288fbb
commit ad1e815277

15
wcurl
View file

@ -66,24 +66,21 @@ done
# being appended to the command is the first one or not. That's because once we # being appended to the command is the first one or not. That's because once we
# are appending any URLs after the first one, we need to also make use of the # are appending any URLs after the first one, we need to also make use of the
# "--next" parameter. # "--next" parameter.
declare -r command_to_eval_init="curl --parallel" declare -r command_to_exec_init="curl --parallel"
command_to_eval="$command_to_eval_init" command_to_exec="$command_to_exec_init"
declare -r per_url_parameters="--location --remote-name --remote-time --retry 10 --retry-max-time 10 $curl_opts --continue-at -" declare -r per_url_parameters="--location --remote-name --remote-time --retry 10 --retry-max-time 10 $curl_opts --continue-at -"
# If we have URLs to download. # If we have URLs to download.
if (( ${#urls_to_download[@]} != 0 )); then if (( ${#urls_to_download[@]} != 0 )); then
for url in "${urls_to_download[@]}"; do for url in "${urls_to_download[@]}"; do
# If this is the first command we've added, don't prepend "--next" to it. # If this is the first command we've added, don't prepend "--next" to it.
if [[ "$command_to_eval" == "$command_to_eval_init" ]]; then if [[ "$command_to_exec" == "$command_to_exec_init" ]]; then
command_to_eval="$command_to_eval $per_url_parameters $url" command_to_exec="$command_to_exec $per_url_parameters $url"
else else
command_to_eval="$command_to_eval --next $per_url_parameters $url" command_to_exec="$command_to_exec --next $per_url_parameters $url"
fi fi
done done
fi fi
# Print command_to_eval if the debug environment variable is set.
[[ -z "${WCURL_DEBUG}" ]] || echo "$command_to_eval"
# Call curl with the generated parameters. # Call curl with the generated parameters.
eval "$command_to_eval" exec $command_to_exec