grep -c prints zero and exits one, so every echo-0 fallback produced a two-line count

This commit is contained in:
Gmer4Lfe
2026-08-06 22:31:50 -04:00
parent 7b2f79e3ac
commit 1b46033584
11 changed files with 32 additions and 22 deletions
+3 -3
View File
@@ -173,7 +173,7 @@ TOTAL_RECLAIMED=0
# ── Step 1 (--all only): remove stopped containers ────────────────────────────
if [[ "$ALL_MODE" == true ]]; then
STOPPED_IDS=$(docker ps -a --filter "status=exited" --filter "status=created" -q 2>/dev/null)
STOPPED_COUNT=$(echo "$STOPPED_IDS" | grep -c . || echo 0)
STOPPED_COUNT=$(echo "$STOPPED_IDS" | grep -c . || true)
if [[ "$STOPPED_COUNT" -eq 0 ]]; then
echo "No stopped containers"
@@ -198,11 +198,11 @@ if [[ "$ALL_MODE" == true ]]; then
# Images not used by any running container
RUNNING_IMAGES=$(docker ps --format "{{.Image}}" 2>/dev/null)
UNUSED_COUNT=$(docker images --format "{{.Repository}}:{{.Tag}}" 2>/dev/null \
| grep -vxF "$RUNNING_IMAGES" | grep -c . || echo 0)
| grep -vxF "$RUNNING_IMAGES" | grep -c . || true)
TARGET_LABEL="$UNUSED_COUNT unused image(s)"
else
DANGLING_IDS=$(docker images -f "dangling=true" -q 2>/dev/null)
UNUSED_COUNT=$(echo "$DANGLING_IDS" | grep -c . || echo 0)
UNUSED_COUNT=$(echo "$DANGLING_IDS" | grep -c . || true)
TARGET_LABEL="$UNUSED_COUNT dangling image(s)"
fi