Language
2008. 3. 17. 09:18
모든 파일명을 변경하는 스크립트다.
대문자->소문자, 소문자->대문자로 변환이 가능하다.
사용법: foo.sh {upper|lower}
#!/bin/bash
# Set variable
caseSwitch=${1}
execCNT=1
caseSwitch=${1}
execCNT=1
# Switch Check
if [ ! ${caseSwitch} ]; then
echo "Usage: {upper|lower}"
exit 0
fi
if [ ! ${caseSwitch} ]; then
echo "Usage: {upper|lower}"
exit 0
fi
# Excute Check
if [ "${caseSwitch}" == "upper" ]; then
echo -n "Do you want change entire files to upper-case? ex)foobar->FOOBAR (Y/[N]) : "
read acceptYN
if [[ "${acceptYN}" =~ '^(y|Y)$' ]]; then
regexCode="'a-z' 'A-Z'"
else
exit 0
fi
elif [ "${caseSwitch}" == "lower" ]; then
echo -n "Do you want change entire files to lower-case? ex)FOOBAR->foobar (Y/[N]) : "
read acceptYN
if [[ "${acceptYN}" =~ '^(y|Y)$' ]]; then
regexCode="'A-Z' 'a-z'"
else
exit 0
fi
else
exit 0
fi
if [ "${caseSwitch}" == "upper" ]; then
echo -n "Do you want change entire files to upper-case? ex)foobar->FOOBAR (Y/[N]) : "
read acceptYN
if [[ "${acceptYN}" =~ '^(y|Y)$' ]]; then
regexCode="'a-z' 'A-Z'"
else
exit 0
fi
elif [ "${caseSwitch}" == "lower" ]; then
echo -n "Do you want change entire files to lower-case? ex)FOOBAR->foobar (Y/[N]) : "
read acceptYN
if [[ "${acceptYN}" =~ '^(y|Y)$' ]]; then
regexCode="'A-Z' 'a-z'"
else
exit 0
fi
else
exit 0
fi
# Change Excute
for list in *
do
orig_name=`basename $list`
conv_name=`echo ${orig_name} | tr ${regexCode}`
if [ "${orig_name}" != "${conv_name}" ]; then
echo "[${execCNT}] ${orig_name} -> ${conv_name}"
mv ${orig_name} ${conv_name}
let "execCNT+=1"
fi
done
for list in *
do
orig_name=`basename $list`
conv_name=`echo ${orig_name} | tr ${regexCode}`
if [ "${orig_name}" != "${conv_name}" ]; then
echo "[${execCNT}] ${orig_name} -> ${conv_name}"
mv ${orig_name} ${conv_name}
let "execCNT+=1"
fi
done
exit 0