Commit
b758bc5bc4b35db0bc807d3ab33cd492e86d6b4d
l10n: AGENTS.md: fix counter fallbacks
Reading a counter with "cmd || echo 0" breaks whenever the command
writes output but still exits non-zero. On zero matches, "grep -c"
prints 0 and exits with status 1, so the command substitution
captured two zeros and the arithmetic that follows failed with a
syntax error instead of evaluating to 0.
Fix by ignoring the exit status with "|| true" and defaulting the
empty value with "${VAR:-0}". Apply this to ENTRY_COUNT in both
l10n_one_batch() and review_one_batch(), and to the BATCH counter
read from po/review-batch.txt, which used the same fragile fallback.
Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Jiang Xin <worldhello.net@gmail.com> · 2026-09-17 07:21 UTC
1 file changed,
+6
−4
modified po/AGENTS.md
| @@ -543,9 +543,9 @@ step 8 after step 6. | |||
| 543 | 543 | DONE_PO="po/l10n-done.po" | |
| 544 | 544 | rm -f "$TODO_JSON" "$TODO_PO" "$DONE_JSON" "$DONE_PO" | |
| 545 | 545 | ||
| 546 | - | ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || echo 0) | |
| 546 | + | ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || true) | |
| 547 | + | ENTRY_COUNT=${ENTRY_COUNT:-0} | |
| 547 | 548 | ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0)) | |
| 548 | - | ||
| 549 | 549 | if test "$ENTRY_COUNT" -gt $min_batch_size | |
| 550 | 550 | then | |
| 551 | 551 | if test "$ENTRY_COUNT" -gt $((min_batch_size * 8)) | |
| @@ -772,7 +772,8 @@ already present. | |||
| 772 | 772 | cp "$INPUT_PO" "$PENDING" | |
| 773 | 773 | fi | |
| 774 | 774 | ||
| 775 | - | ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || echo 0) | |
| 775 | + | ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || true) | |
| 776 | + | ENTRY_COUNT=${ENTRY_COUNT:-0} | |
| 776 | 777 | ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0)) | |
| 777 | 778 | if test "$ENTRY_COUNT" -eq 0 | |
| 778 | 779 | then | |
| @@ -796,7 +797,8 @@ already present. | |||
| 796 | 797 | NUM=$ENTRY_COUNT | |
| 797 | 798 | fi | |
| 798 | 799 | ||
| 799 | - | BATCH=$(cat "$BATCH_FILE" 2>/dev/null || echo 0) | |
| 800 | + | BATCH=$(cat "$BATCH_FILE" 2>/dev/null || true) | |
| 801 | + | BATCH=${BATCH:-0} | |
| 800 | 802 | BATCH=$((BATCH + 1)) | |
| 801 | 803 | echo "$BATCH" >"$BATCH_FILE" | |
| 802 | 804 | ||