Miscellany
public text v1 · immutable#!/bin/sh
function print_usage {
cat <<-EOS
$0
Tidy all files in current directory
Arguments:
-o overwrite originals (otherwise makes .tidied files)
-h print this message
-? pring this message
EOS
}
while getopts "oh" options; do
case $options in
o) overwrite=1;;
h) print_usage
exit 1;;
\?) print_usage
exit 1;;
*) print_usage
exit 1;;
esac
done
if [ "`tidy -v 2>/dev/null`" = '' ]; then
echo "Can't find tidy. Exiting"
exit 0
fi
for file in `ls -1 *.xml`; do
`tidy -xml -i -w 150 ${file} 2>/dev/null >tmp.xml`
if [ -e tmp.xml ]; then
if [ -z "$overwrite" ]; then
mv tmp.xml ${file}_tidied
fi
if [ -n "$overwrite" ]; then
mv tmp.xml $file
fi
fi
done