Updated Sc2045 (markdown)

koalaman
2014-05-08 19:22:55 -07:00
parent b616d51abb
commit e2774d798a

@@ -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: ### Problematic code:
@@ -14,6 +14,8 @@
echo "$f" echo "$f"
done 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: ### 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). 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).