Updated Sc2045 (markdown)

koalaman
2014-05-08 19:35:52 -07:00
parent 63ad6195a1
commit 6cef6f67f3

@@ -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'.
## Iterating over ls output is fragile. Use globs.
### Problematic code:
@@ -11,10 +11,11 @@
for f in *.wav
do
[[ -e $f ]] || break # handle the case of no *.wav files
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. There are [several other conditions](http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29) to look out for. )
Also note that in Bash, `shopt -s nullglob` will allow the loop to run 0 times instead of 1 if there are no matches. There are also [several other conditions](http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29) to be aware of.
### Rationale: