On Sat, Apr 12, 2008 at 09:52:47AM -0600, Stuart Jansen wrote: > Ever since I was taught "while read" as a method to avoid whitespace > problems, it has been one of my favorite shell scripting tricks. > Unfortunately, while working on a git script yesterday, I discovered an > instance where it doesn't work. Specifically, Bash is leaking the output > of find to the screen and horking stdin. > > I found a workaround, but it's more complex than I like. I've included > three generations of a simplified script as an example. What I'd like to > know is, does anyone know a more sane method for looping over a list of > files produced by a command like find, git or anything else? > > NOTE: To save time, let me point out that git doesn't have an equivalent > of find's --exec, so that's out. In addition, the script has to handle > whitespace in filenames so "for FILE in $( ... )" is also out. I have a > sneaking suspicion that changing $IFS could lead to a solution, but that > just freaks me out.
Yep, changing IFS gives a very simple solution:
OLDIFS=$IFS
# the single quote on the next line is followed by a newline
IFS='
'
for FILE in $(find . -name \*.txt); do
echo Spell checking $FILE
aspell -c "$FILE"
done
IFS=$OLDIFS
--
Byron Clark
signature.asc
Description: Digital signature
/* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
