Skip to content

iterate-ls-output

Shellsuspiciousno fixdefault: warnshell/shellcheck

Reports a for loop over the output of ls.

ls output is for people. It is split on blanks and globbed, a file name with a space or a newline breaks the loop, and ls may change the names it prints.

To fix, loop over a glob: for f in ./*.

Reported
...
[ -z "$x" ]
for f in $(ls); do :; done
for f in `ls /tmp`; do :; done
for f in *.txt; do :; done
...
shell:
lint:
rules:
iterate-ls-output: warn # off, warn (default), error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line iterate-ls-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 SC2045 full