Skip to content

Instantly share code, notes, and snippets.

@ecylmz
Created September 26, 2011 18:16
Show Gist options
  • Save ecylmz/1242919 to your computer and use it in GitHub Desktop.
Save ecylmz/1242919 to your computer and use it in GitHub Desktop.
hmm [sh]
#!/bin/sh
if [ $# -eq 0 ];
then
echo usage $0 files ...
exit 1
fi
for file in $*;
do
echo "# Processing: $file" 1>&2
if [ ! -f "$file" ];
then
echo Not a file: "$file" 1>&2
exit 1
fi
TYPE=`file - < "$file" | cut -d: -f2`
if echo "$TYPE" | grep -q '(with BOM)';
then
echo "# $file already has BOM, skipping." 1>&2
else
( mv ${file} ${file}~ && uconv -f utf-8 -t utf-8 --add-signature < "${file}~" > "${file}" ) || ( echo Error processing "$file" 1>&2 ; exit 1)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment