Skip to content

iterate-file-output

Shellsuspiciousno fixdefault: offshell/shellcheck

Reports a for loop over the output of cat, sort, sed, head or tail.

The output is split on blanks and globbed, not on lines, so a line with a space becomes several items, and a * in the file expands to file names.

To fix, read lines: while IFS= read -r line; do ...; done < file.

Reported
...
x=$(echo "a" | tr a b)
...
for l in $(cat file); do :; done
for l in "$@"; do :; done
...
shell:
lint:
rules:
iterate-file-output: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line iterate-file-output 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 SC2013 partial Only a for over cat, sort, sed, head or tail output.