. 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 Extension: " 0
EXT1=$_STR
echo "Target Extension is \"${EXT1}\""
ask_string "Input replace Extension: " 0
EXT2=$_STR
echo "Replace Extension is \"${EXT2}\""
NUM=0
for FNAME in $_DIRNAME/*.$EXT1; do
if [ -f "$FNAME" ]; then
mv $FNAME ${FNAME%"$EXT1"}$EXT2
NUM=$(expr $NUM + 1)
fi
done
if [ $NUM -eq 0 ]; then
echo "No file."
else
echo "*** Successful."
fi
unset _DIRNAME EXT1 EXT2 FNAME NUM _STR
$ ls
a1.txt a2.txt a3.txt a4.txt a5.txt
$ ./rep_extensions.sh
Input Directory (Blank is Cancel.) : .
Target directory is "."
Input Target Extension: txt
Target Extension is "txt"
Input replace Extension: text
Replace Extension is "text"
*** Successful.
$ ls
a1.text a2.text a3.text a4.text a5.text