On Sun, Mar 09, 2014 at 01:21:35PM +0100, Martin wrote:
> files=$(find . -type f -newer .before_start_offlineimap | grep new)
>
> for f in ${files}
This code is extremely dangerous, because file names can contain
whitespace characters and shell globbing characters. Any whitespace
or matched glob in a filename will break this code.
Replace it with a loop reading from a process substitution:
while IFS= read -r f; do
...
done < <(find . -type f -newer .before_start_offlineimap -path '*new*')
(assuming your find(1) has the nonstandard -path argument).
Even the loop that I wrote just now will break if filenames contain
newline characters. If you want 100% reliability, even when the
filenames contain newlines, then you also need a version of find with
the -print0 argument:
while IFS= read -r -d '' f; do
...
done < <(find . -type f -newer .before_start_offlineimap -path '*new*' -print0)
(In theory you could use -exec printf '%s\0' {} + as a replacement for
-print0, but I suspect you're probably on GNU/Linux which should have
both -path and -print0, so it shouldn't be a problem.)