Re: calling script function on output of find



John Stumbles <john.stumbles@xxxxxxxxxxxx> wrote:
On Tue, 05 Jul 2011 19:17:29 +0100, Dave Gibson wrote:

find "$SOURCE_DIR" -type f -size +0 | while IFS= read -r f ; do
process_file "$f"
done

One question: why the -r switch ("Backslash does not act as an escape
character") to read?

To ensure that a backslash has the same meaning in read's input as it
does in find's output.

In an empty directory:

$ touch 'foo\bar'
$ find . -name 'foo*'
./foo\bar
$ find . -name 'foo*' | { read f ; printf '%s\n' "$f" ; }
./foobar
$ find . -name 'foo*' | { read -r f ; printf '%s\n' "$f" ; }
./foo\bar
.



Relevant Pages