Skip to content

Instantly share code, notes, and snippets.

@CLCL
Last active January 2, 2016 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CLCL/8330798 to your computer and use it in GitHub Desktop.
Save CLCL/8330798 to your computer and use it in GitHub Desktop.
bom_check.sh PHPとかHTMLにBOM付きUTF-8があるかどうか探す あったらリスト表示して終了コード255 無かったら何も表示せず終了コード0
#!/bin/bash
##########################################################
#
# bom_check.sh : BOM付きファイルを検索してレポート
# findでbash依存の記述($'\xef\xbb\xbf')をしているので、bashでないと動かない
#
##########################################################
CMDNAME=`basename $0`
if [ $# -ne 1 ]; then
cat <<EOS 1>&2
指定されたディレクトリ内のhtml/htm/phpファイルで、BOM付きUTF-8のファイルを表示します。
使用法: $CMDNAME [ディレクトリ]
EOS
exit 1
fi
TARGETDIR=$1
# BOM付きテキストファイルを探すコマンド
OPTIONS="-regex '.*adodb.*' -prune -o "
LS=`find $TARGETDIR $OPTIONS \( -name '*.htm*' -o -name '*.php' \) -exec grep -l -e $'\xef\xbb\xbf' {} + | sed -e 's/ /\\n/g'`
# もし見つからなかったら、終わる
if [ "$LS" = "" ]; then
exit 0
fi
echo "BOM付きファイル:"
echo $LS
exit 255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment