Fix grep -c exit code causing arithmetic syntax error#161
Conversation
When `grep -c` finds 0 matches, it outputs "0" to stdout but exits with code 1 (no matches found). The `|| echo "0"` fallback then triggers, appending another "0" to the command substitution output. This results in the variable containing "0\n0" instead of just "0", causing a bash arithmetic syntax error on the $((...)) expression: line 500: 0 0: syntax error in expression (error token is "0") Fix: Replace `|| echo "0"` with `|| true` so the grep output is preserved as-is, with a fallback to set 0 if the variable is empty (which handles actual grep errors like missing files). Affects 3 locations in ralph_loop.sh (lines 498, 499, 605). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
WalkthroughModified error-handling patterns in two functions of Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fix arithmetic syntax errors by making
|
Summary
grep -coutputs"0"to stdout when finding 0 matches, but exits with code 1|| echo "0"fallback triggers on exit code 1, appending another"0"to the output"0\n0"instead of"0", causing bash arithmetic error:line 500: 0 0: syntax error in expressionralph_loop.sh(lines 498, 499, 605)Fix
Replace
|| echo "0"with|| trueso grep's stdout output is preserved. Add[[ -z "$var" ]] && var=0fallback for actual errors (e.g. missing file).Test plan
fix_plan.mdthat has only unchecked- [ ]items (0 completed) — previously crashed herefix_plan.mdthat has some- [x]itemsfix_plan.mdpresent🤖 Generated with Claude Code
Summary by CodeRabbit