Skip to content

iterate-find-output

Shellsuspiciousno fixdefault: warnshell/shellcheck

Reports a for loop over the output of find.

The output is split on blanks and globbed, so a file name with a space is cut into several items, and one with a * or ? expands to other names.

To fix, use find ... -exec, or find ... -print0 | while IFS= read -r -d '' f, or a glob (for f in ./*).

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

Enabled by the presets: shell/shellcheck.

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

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
shellcheck SC2044 full