Make shell script robust against spaces in file names

Also
* Simplify wc.
* Add period at end of sentences.
* Use tabs instead of spaces for indenting.
* Add newline at end of file.

Change-Id: I50a9d31acecc32bcf693cba5022152aa9abcbaab
This commit is contained in:
Fomafix 2017-08-30 12:22:40 +02:00
parent a178885b5b
commit db97b4e202
1 changed files with 12 additions and 11 deletions

View File

@ -1,17 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
found=0 found=0
for svgfile in `find resources -type f -name "*.svg"`; do find resources -type f -name '*.svg' |
outfile="$svgfile.tmp" while read svgfile; do
node_modules/.bin/svgo --config .svgo.yml -i $svgfile -o $outfile -q outfile="$svgfile.tmp"
if [ $(wc -c $svgfile | awk '{print $1}') -gt $(wc -c $outfile | awk '{print $1}') ]; then node_modules/.bin/svgo --config .svgo.yml -i "$svgfile" -o "$outfile" -q
echo "File $svgfile is not compressed" if [ $(wc -c < "$svgfile") -gt $(wc -c < "$outfile") ]; then
found=$((found + 1)) echo "File $svgfile is not compressed."
fi found=$((found + 1))
rm $outfile fi
rm "$outfile"
done done
if [ $found -gt 0 ]; then if [ $found -gt 0 ]; then
echo "Found $found uncompressed SVG files. Please compress the files and re-submit the patch" echo "Found $found uncompressed SVG files. Please compress the files and re-submit the patch."
exit 1 exit 1
fi fi