Skip to content
shiporbreak

No streak yet

Sign in

November 22, 2026 路 #67

BashMediumOpen write-up

The comparison that wrote a file

The alert fires every run, even with 3 errors, and a file named 100 appears in the working directory. Which line is wrong?

#!/usr/bin/env bash
count=$(grep -c ERROR /var/log/app.log || true)

if [ "$count" > 100 ]; then
  ./notify.sh "error spike: ${count}"
fi

Next puzzle in UTC

One try. The first answer sticks.

How to fix it

The shell sees [ "$count" ] with stdout redirected to 100. A non-empty string is true, so it always alerts. Use -gt, or (( count > 100 )).

[ is an ordinary command, so the shell parses > 100 as a redirection before [ ever runs. The command becomes [ "$count" ], which is true for any non-empty string, including "3". As a side effect, a file named 100 is created. Inside [[ ]], > is a string comparison, which is also wrong for numbers because "3" sorts after "100".

Fix

if [ "$count" -gt 100 ]; then
  ./notify.sh "error spike: ${count}"
fi

Or use arithmetic: if (( count > 100 )); then. ShellCheck flags the original as SC2065, and the [[ ]] version as SC2071.

Sponsor this spot

Put your tool on the puzzle
One labeled card, in front of engineers who show up every day from YouTube, TikTok, and Instagram.