mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-04 03:46:06 +08:00
Updated Sc2045 (markdown)
@@ -1,4 +1,4 @@
|
||||
# Iterate over globs whenever possible (e.g. 'for f in */*.wav'), as for loops over ls will fail for filenames like 'my file*.txt'.
|
||||
## Iterate over globs whenever possible (e.g. 'for f in */*.wav'), as for loops over ls will fail for filenames like 'my file*.txt'.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
echo "$f"
|
||||
done
|
||||
|
||||
(also note that in Bash, `shopt -s nullglob` will allow the loop to run 0 times instead of 1 if there are no matches)
|
||||
|
||||
### Rationale:
|
||||
|
||||
When looping over a set of files, it's always better to use globs when possible. Using command expansion causes word splitting and glob expansion, which will cause problems for certain filenames (typically first seen when trying to process a file with spaces in the name).
|
||||
|
Reference in New Issue
Block a user