[CentOS] Shell Script Pointers?

Wed May 20 05:21:25 UTC 2009
Stuart Jansen <sjansen at gurulabs.com>

On Tue, 2009-05-19 at 22:06 -0400, Eric Sisolak wrote:
> Also you could try
> 
> for FOLDER in `find /usr/local/squidGuard/db -maxdepth 1 -type d`; do

This is a classic mistake. It has two problems:
1) The list of files created by the embedded find can exceed the maximum
command length.
2) Directories with spaces in their name will be split by the tokenizer,
resulting in $FOLDER containing invalid or dangerous paths.

> instead of
> find /usr/local/squidGuard/db -maxdepth 1 -type d | while read FOLDER; do

This is the correct way to combine a shell loop with a program that
creates a list of files.