[Shell command] Skip the xargs command when there is no input

Created on November 30, 2026

By default, GNU xargs runs the command once even if it reads no arguments. For example, this pipeline runs mkdir without a directory name, so mkdir reports a missing operand.

printf '\n' | xargs mkdir

Use -r or --no-run-if-empty to skip the command when there are no arguments.

printf '\n' | xargs --no-run-if-empty mkdir

The second command produces no output.

Shell command