From 0bbeeffc7c8810d7df4d9a0d46cff236db017665 Mon Sep 17 00:00:00 2001 From: Dossy Shiobara Date: Mon, 16 Dec 2024 20:23:28 -0500 Subject: [PATCH] fix: handle case correctly when `shim_args` is empty --- lib/commands/command-exec.bash | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/commands/command-exec.bash b/lib/commands/command-exec.bash index cb56b36c..23402374 100644 --- a/lib/commands/command-exec.bash +++ b/lib/commands/command-exec.bash @@ -3,7 +3,11 @@ shim_exec_command() { local shim_name shim_name=$(basename "$1") - local shim_args=("${@:2}") + + local shim_args=() + if [ $# -gt 1 ]; then + shim_args=("${@:2}") + fi if [ -z "$shim_name" ]; then printf "usage: asdf exec \n" @@ -20,12 +24,25 @@ shim_exec_command() { exit 2 fi - asdf_run_hook "pre_${plugin_name}_${shim_name}" "${shim_args[@]}" - pre_status=$? + # Check if array is empty before using it + if [ ${#shim_args[@]} -eq 0 ]; then + asdf_run_hook "pre_${plugin_name}_${shim_name}" + pre_status=$? + else + asdf_run_hook "pre_${plugin_name}_${shim_name}" "${shim_args[@]}" + pre_status=$? + fi + if [ "$pre_status" -ne 0 ]; then return "$pre_status" fi - exec "$executable_path" "${shim_args[@]}" + + # Check if array is empty before using it + if [ ${#shim_args[@]} -eq 0 ]; then + exec "$executable_path" + else + exec "$executable_path" "${shim_args[@]}" + fi } with_shim_executable "$shim_name" exec_shim || exit $?