Skip to content

find-xargs-print0

Shellsuspiciousno fixdefault: warnshell/shellcheck

Reports a pipeline from find into xargs without -print0 and -0.

xargs splits its input on blanks and treats quotes and backslashes in it specially, and find writes one file name per line. A file name with a space, a quote or a newline is cut into pieces, and the command runs on wrong files.

To fix, use find ... -print0 | xargs -0 ... (or find -exec).

Reported
...
for f in *.txt; do :; done
...
find . | xargs rm
find . -print0 | xargs -0 rm
find . | xargs -0 rm
find . -name x | wc -l
shell:
lint:
rules:
find-xargs-print0: warn # off, warn (default), error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line find-xargs-print0 in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
shellcheck SC2038 partial Only a find ... | xargs pipeline in one statement.