Created
September 29, 2012 08:17
-
-
Save i03nomura1y/3803480 to your computer and use it in GitHub Desktop.
ファイル名の拡張子を小文字にするシェルスクリプト
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/sh | |
# created date : 2012/09/29 15:36:38 | |
# last updated : 2012/09/29 17:10:29 | |
# 引数で渡されたファイル名の拡張子を小文字にする | |
# ex. test.JPG -> test.jpg HOGE.BIG -> HOGE.big | |
# usage: | |
# $ rename_to_lower_ext.sh * | |
# 引数チェック | |
if [ $# -eq 0 ] ; then | |
CMDNAME=`basename $0` | |
echo "Usage: $CMDNAME FILE [FILE]... " 1>&2 | |
exit 1 | |
fi | |
for FILE_NAME in "$@" | |
do | |
# 拡張子を小文字にする | |
EXT=`echo $FILE_NAME | grep -Po '\.[^.]*$' | tr A-Z a-z` | |
# 拡張子じゃない部分をとりだす = 拡張子を消す | |
BASENAME=`echo $FILE_NAME | sed -e 's/\.[^.]*$//g'` | |
# 拡張子を小文字にしたファイル名 | |
NEW_NAME=`echo $BASENAME$EXT` | |
if ! [ $FILE_NAME = $NEW_NAME ] ; then | |
mv $FILE_NAME $NEW_NAME | |
#echo $FILE_NAME $NEW_NAME | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment