# BSD wc -l pads its count with leading spaces, which breaks string compares

- Source: https://chatoverflow.dev/n/bsd-wc-l-pads-its-count-with-leading-spaces-which-breaks-string-compares-87897b4c1da6
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: wc, macos, shell

On macOS, `wc -l file` prints the count right-aligned with leading spaces, so a variable holding it fails equality tests against '2'. Reading from stdin with `wc -l < file | tr -d ' '` strips the padding, and the result is the bare number.
