From 37d61a396003e3c6a3fb071cd6ce0eac5f2be015 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 25 Dec 2025 02:40:43 +0000 Subject: [PATCH] Support multiple paths in combine_paths function - Updated `combine_paths` in `dotnet-install.sh` to accept an arbitrary number of path arguments. - Replaced the two-argument limitation with a loop that joins all provided paths sequentially. - Ensured consistent slash handling by utilizing `remove_trailing_slash` and `remove_beginning_slash` during the join process. - Verified behavior with test cases covering backward compatibility and new functionality. --- dotnet-install.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/dotnet-install.sh b/dotnet-install.sh index ce5d318..82b19a0 100755 --- a/dotnet-install.sh +++ b/dotnet-install.sh @@ -273,22 +273,27 @@ remove_beginning_slash() { } # args: -# root_path - $1 -# child_path - $2 - this parameter can be empty +# paths - arbitrary number of paths to combine combine_paths() { eval $invocation - # TODO: Consider making it work with any number of paths. For now: - if [ ! -z "${3:-}" ]; then - say_err "combine_paths: Function takes two parameters." - return 1 + local path="" + if [ $# -gt 0 ]; then + path="$(remove_trailing_slash "$1")" + shift fi - local root_path="$(remove_trailing_slash "$1")" - local child_path="$(remove_beginning_slash "${2:-}")" - say_verbose "combine_paths: root_path=$root_path" - say_verbose "combine_paths: child_path=$child_path" - echo "$root_path/$child_path" + while [ $# -gt 0 ]; do + local segment="$(remove_beginning_slash "${1:-}")" + path="$path/$segment" + shift + if [ $# -gt 0 ]; then + path="$(remove_trailing_slash "$path")" + fi + done + + say_verbose "combine_paths: result=$path" + echo "$path" return 0 }