Created
April 17, 2018 03:04
-
-
Save fartbagxp/8ee86c849f1be27332dac1378c6759ac to your computer and use it in GitHub Desktop.
Changing to UTF8 BOM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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