kormoc/imgopt — pull request #5 by xavery (2013-09-30 22:09:55+00:00)
Title: Code cleanup for Bash, fix handling of whitespace chars in filenames.

This is a collection of fixes that I felt this script really needed. A
general summary follows :
* Quotes are now used around every variable whose value may contain
whitespace characters. This enables the script to handle whitespace
characters in file and directory names.
* Local variables are used in functions wherever possible. This is to
make the locality of those variables explicit and avoid possible name
clashes between different functions.
* The code style was made more uniform : $() is now used for command
substitution instead of ``, if/then style is now the same across every
file, arithmetic expansion is used instead of "let".
* Bash's "new test" ([[ and ]]) is used in all cases. The "old" test
(single brackets) should be used only when compatibility with sh is
needed, and I doubt if this is the case here.
* Process substitution is now used to obtain the list of file names
from find, protecting from weird filenames (with things like newlines in
them). Also, only one stat is used to get the file's attributes.
* Parsing the output of ls must always be avoided at all costs. Stat
was used to get the file size instead of ls.