Skip to content

Instantly share code, notes, and snippets.

@fartbagxp
Created April 17, 2018 03:04
Show Gist options
  • Save fartbagxp/8ee86c849f1be27332dac1378c6759ac to your computer and use it in GitHub Desktop.
Save fartbagxp/8ee86c849f1be27332dac1378c6759ac to your computer and use it in GitHub Desktop.
Changing to UTF8 BOM
#!/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