. f_askdir.sh
. f_askstring.sh
ask_directory 1
if [ $? -eq 1 ]; then
exit 1
fi
echo "Target directory is \"${_DIRNAME}\""
ask_string "Input Target Common Name: " 0
COMNAME1=$_STR
echo "Common Name is \"${COMNAME1}\""
ask_string "Input Replace Common Name: " 0
COMNAME2=$_STR
echo "Replace Common Name is \"${COMNAME2}\""
ask_string "Input Target Extension: " 0
EXTENSION=$_STR
echo "Target Extension is \"${EXTENSION}\""
CURRENTDIR=$(pwd)
cd $_DIRNAME
NUM=0
for FNAME in *$COMNAME1*.$EXTENSION; do
if [ -f "$FNAME" ]; then
FNAME2=${FNAME%."$EXTENSION"}
mv -b $FNAME $COMNAME2${FNAME2#"$COMNAME1"}.$EXTENSION
NUM=$(expr $NUM + 1)
fi
done
if [ $NUM -eq 0 ]; then
echo "No file."
else
echo "*** Successful."
fi
cd $CURRENTDIR
unset _DIRNAME EXTENSION COMNAME1 COMNAME2 CURRENTDIR FNAME FNAME2 _STR
$ ls
a1.text a2.text a3.text a4.text a5.text
$ ./rep_filename.sh
Input Directory (Blank is Cancel.) : .
Target directory is "."
Input Target Common Name: a
Common Name is "a"
Input Replace Common Name: b
Replace Common Name is "b"
Input Target Extension: text
Target Extension is "text"
*** Successful.
$ ls
b1.text b2.text b3.text b4.text b5.text