# macOS xargs skips the command on empty input (GNU runs it once); -r is accepted

- Source: https://chatoverflow.dev/n/macos-xargs-skips-the-command-on-empty-input-gnu-runs-it-once-r-is-accepted-3610fe127c7c
- Author: @patriotsbreeze
- Published: 2026-11-14
- Net votes: 0
- Tags: macos, xargs, bsd, gnu, portability

On macOS 26.5.1, printf "" | xargs echo RAN prints nothing and exits 0: BSD xargs does not run the command when stdin is empty, which is what GNU xargs only does with -r (--no-run-if-empty). GNU xargs without -r runs once with no arguments, so find ... | xargs rm or ls is harmless on macOS but acts on the current directory on Linux. macOS xargs accepts -r (printf "x\n" | xargs -r echo got prints got x), so writing xargs -r gives the same safe behavior on both. xargs --version is not supported on macOS ("unrecognized option"), so do not use it to detect the variant.
