拡張子を一括して付加する

#!/bin/sh
#add_extension.sh

. f_askdir.sh
. f_askstring.sh

ask_directory 1
if [ $? -eq 1 ]; then
    exit 1
fi
echo "Target directory is \"${_DIRNAME}\""

echo " 1) All files"
echo " 2) Start Character"
echo " 3) End Character"
echo " 4) Includes Character"
echo -n " Select Number: "

while read ANSWER; do
    case "${ANSWER}" in
        1) SELNAME=* ; break ;;
        2) ask_string "Start string of filename: " 0
            SELNAME=$_STR* ; break ;;
        3) ask_string "End of filename: " 0
            SELNAME=*$_STR ; break ;;
        4) ask_string "Include string of filename: " 0
            SELNAME=*$_STR* ; break ;;
        *) echo "*** Menu not found." ;;
    esac
    echo -n " Select Number: "
done

ask_string "Input add extension: " 0
EXTENSION=$_STR
echo "Add Extension is \"${EXTENSION}\""

NUM=0
for FNAME in $_DIRNAME/$SELNAME ; do
    if [ -f "$FNAME" ]; then
        mv $FNAME $FNAME.$EXTENSION
        NUM=$(expr $NUM + 1)
    fi
done
if [ $NUM -eq 0 ]; then
    echo "No file."
else
    echo "*** Successful."
fi

unset _DIRNAME ANSWER SELNAME EXITENSION FNAME NUM _STR
$ ls 1
A001.TXT  A003.TXT  A005.TXT  A007.TXT  A009.TXT
A002.TXT  A004.TXT  A006.TXT  A008.TXT  A010.TXT

$ ./add_extension.sh 
Input Directory (Blank is Cancel.) : 1
Target directory is "1"
 1) All files
 2) Start Character
 3) End Character
 4) Includes Character
 Select Number: 1
Input add extension: bak
Add Extension is "bak"
*** Successful.

$ ls 1
A001.TXT.bak  A003.TXT.bak  A005.TXT.bak  A007.TXT.bak  A009.TXT.bak
A002.TXT.bak  A004.TXT.bak  A006.TXT.bak  A008.TXT.bak  A010.TXT.bak