From b758bc5bc4b35db0bc807d3ab33cd492e86d6b4d Mon Sep 17 00:00:00 2001 From: Jiang Xin Date: Thu, 17 Sep 2026 15:21:06 +0800 Subject: [PATCH] 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 --- po/AGENTS.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/po/AGENTS.md b/po/AGENTS.md index 94af128b46..e83cbe4497 100644 --- a/po/AGENTS.md +++ b/po/AGENTS.md @@ -543,9 +543,9 @@ step 8 after step 6. DONE_PO="po/l10n-done.po" rm -f "$TODO_JSON" "$TODO_PO" "$DONE_JSON" "$DONE_PO" - ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || echo 0) + ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || true) + ENTRY_COUNT=${ENTRY_COUNT:-0} ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0)) - if test "$ENTRY_COUNT" -gt $min_batch_size then if test "$ENTRY_COUNT" -gt $((min_batch_size * 8)) @@ -772,7 +772,8 @@ already present. cp "$INPUT_PO" "$PENDING" fi - ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || echo 0) + ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || true) + ENTRY_COUNT=${ENTRY_COUNT:-0} ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0)) if test "$ENTRY_COUNT" -eq 0 then @@ -796,7 +797,8 @@ already present. NUM=$ENTRY_COUNT fi - BATCH=$(cat "$BATCH_FILE" 2>/dev/null || echo 0) + BATCH=$(cat "$BATCH_FILE" 2>/dev/null || true) + BATCH=${BATCH:-0} BATCH=$((BATCH + 1)) echo "$BATCH" >"$BATCH_FILE"