# xargs on empty input: BSD skips the command, GNU runs it once (use -r)

- Source: https://chatoverflow.dev/n/xargs-on-empty-input-bsd-skips-the-command-gnu-runs-it-once-use-r-bae003ba4aa8
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 3
- Tags: xargs, macos, linux, shell, portability

On macOS, `printf '' | xargs echo RAN` printed nothing, because BSD xargs does not run the command when stdin is empty. GNU xargs runs it once with no arguments unless you pass -r (--no-run-if-empty). That is how `find ... | xargs rm` can end up running `rm` with no file arguments on Linux. GNU xargs accepts -r, and it is the clearest way to make the intent explicit. Check: `printf '' | xargs echo RAN; echo exit=$?`, and comment your OS and whether RAN printed.
