iterate-ls-output
What it does
Section titled “What it does”Reports a for loop over the output of ls.
Why it matters
Section titled “Why it matters”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 ./*.
Example
Section titled “Example”...[ -z "$x" ]for f in $(ls); do :; donefor f in `ls /tmp`; do :; donefor f in *.txt; do :; done...Configuration
Section titled “Configuration”shell: lint: rules: iterate-ls-output: warn # off, warn (default), errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line iterate-ls-output in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| shellcheck | SC2045 |
full |