Table of Contents

bash loop

while read

for

for file in `ls -1L`;do
du -h -d 0 $file
done

Another example showing how to set up new folders with git repo's:

$ mkdir ~/git
$ cd ~/git
$ for i in a b c d
do
        mkdir $i
        cd $i
        git init
        echo "module $i" > $i.txt
        git add $i.txt
        git commit -m "Initial commit, submodule $i"
        cd ..
done

original url: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#submodules

other notes

Props to this post, this is a very elegant solution to weird characters in filenames:
http://www.macgeekery.com/tips/cli/h...spaces_in_bash
Code:

find . -type f -print | while read i; do touch "${i}"; done


    That will fail if any filenames have leading or trailing spaces or end in a backslash. (Not to mention filenames containing newlines.)

Quote:
'for' splits on spaces. Period. Regardless of quoting.


    It does not split on spaces if there is no space in the value of $IFS.

Quote:
'read' does not.


    It does if more than one variable is given as an argument (and IFS contains a space).