Skip to content

Fix empty array crash on bash 3.2 in setup-ralph-loop.sh#497

Open
LuciferDono wants to merge 1 commit intoanthropics:mainfrom
LuciferDono:LuciferDono/fix-bash32-empty-array
Open

Fix empty array crash on bash 3.2 in setup-ralph-loop.sh#497
LuciferDono wants to merge 1 commit intoanthropics:mainfrom
LuciferDono:LuciferDono/fix-bash32-empty-array

Conversation

@LuciferDono
Copy link

Summary

setup-ralph-loop.sh crashes with PROMPT_PARTS[*]: unbound variable on macOS when invoked without arguments. This prevents the script from reaching its built-in error handling, which provides a helpful "No prompt provided" message with usage examples.

Fixes #492, fixes #472.

Root Cause

Line 6 sets set -euo pipefail. The -u (nounset) flag causes bash 3.2 (macOS default at /bin/bash) to treat empty array expansion ${array[*]} as an unbound variable. Line 113 expands ${PROMPT_PARTS[*]} which crashes before reaching the validation on line 116.

Change

Single-line fix on line 113:

-PROMPT="${PROMPT_PARTS[*]}"
+PROMPT="${PROMPT_PARTS[*]:-}"

The :- parameter expansion provides an empty string default when the array is empty, which is standard POSIX shell syntax. This allows execution to reach the existing error handler on lines 116-128.

After the fix

$ bash setup-ralph-loop.sh
❌ Error: No prompt provided

   Ralph needs a task description to work on.

   Examples:
     /ralph-loop Build a REST API for todos
     /ralph-loop Fix the auth bug --max-iterations 20
     /ralph-loop --completion-promise 'DONE' Refactor code

   For all options: /ralph-loop --help

Testing

Scenario Expected Result
No arguments "No prompt provided" error (exit 1) PASS
With arguments ("hello" --max-iterations 3) Normal activation (exit 0) PASS
--help Usage text (exit 0) PASS
Options only, no prompt (--max-iterations 10) "No prompt provided" error (exit 1) PASS
Full options with completion promise State file generated, promise displayed PASS

PROMPT_PARTS is the only array expansion in the script — no other instances of this bug exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant