From 6cef6f67f349281a2d2210fada4b604415bd8bad Mon Sep 17 00:00:00 2001 From: koalaman Date: Thu, 8 May 2014 19:35:52 -0700 Subject: [PATCH] Updated Sc2045 (markdown) --- Sc2045.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sc2045.md b/Sc2045.md index a4588f3..fe32c16 100644 --- a/Sc2045.md +++ b/Sc2045.md @@ -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: