From 0635b652b41254635ccb13923b8ba93f07fb66ad Mon Sep 17 00:00:00 2001 From: frankbria Date: Fri, 5 Sep 2025 22:49:52 -0700 Subject: [PATCH] Fix grep -c fallback logic causing syntax error in double bracket test The original `|| echo 0` fallback was executing even when grep -c succeeded but returned 0 matches (exit code 1), resulting in "0\n0" being assigned to variables. This multi-line string caused syntax errors in [[ ]] tests. Fixed by removing the fallback and explicitly handling empty variables instead, which properly addresses the root cause of the line 280 error. --- ralph_loop.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ralph_loop.sh b/ralph_loop.sh index 1623dbc..cd45f64 100755 --- a/ralph_loop.sh +++ b/ralph_loop.sh @@ -272,8 +272,12 @@ should_exit_gracefully() { # 4. Check fix_plan.md for completion if [[ -f "@fix_plan.md" ]]; then - local total_items=$(($(grep -c "^- \[" "@fix_plan.md" 2>/dev/null || echo 0))) - local completed_items=$(($(grep -c "^- \[x\]" "@fix_plan.md" 2>/dev/null || echo 0))) + local total_items=$(grep -c "^- \[" "@fix_plan.md" 2>/dev/null) + local completed_items=$(grep -c "^- \[x\]" "@fix_plan.md" 2>/dev/null) + + # Handle case where grep returns no matches (exit code 1) + [[ -z "$total_items" ]] && total_items=0 + [[ -z "$completed_items" ]] && completed_items=0 log_status "INFO" "DEBUG: @fix_plan.md check - total_items:$total_items, completed_items:$completed_items" >&2