Last active
January 2, 2016 16:29
-
-
Save CLCL/8330798 to your computer and use it in GitHub Desktop.
bom_check.sh PHPとかHTMLにBOM付きUTF-8があるかどうか探す
あったらリスト表示して終了コード255
無かったら何も表示せず終了コード0
This file contains 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/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