連番ファイル名の桁数をそろえる

#!/bin/sh
#add_zero.sh

. f_askdir.sh
. f_askstring.sh

ask_directory 2
echo "Target Directory is \"${_DIRNAME}\""

ask_string "Input Common Name: " 0
COMNAME=$_STR
echo "Common Name is \"${COMNAME}\""

ask_string "Input Target Extension: " 0
EXTENTION=$_STR
echo "Target Extension is \"${EXTENTION}\""

CNT=1
NUM=0
while [ $CNT -lt 100 ]; do
    if [ -f "$_DIRNAME/$COMNAME$CNT.$EXTENTION" ]; then
        if [ $CNT -lt 10 ]; then
            NUM=00${CNT}
        else
            NUM=0${CNT}
        fi
        mv $_DIRNAME/$COMNAME$CNT.$EXTENTION $_DIRNAME/$COMNAME$NUM.$EXTENTION
    fi
        CNT=$(expr $CNT + 1 )
done

if [ $NUM -eq 0 ]; then
    echo "No file."
else
    echo "*** Successful."
fi
unset _DIRNAME COMNAME EXTENTION CNT NUM _STR
$ ls
a1.txt a2.txt a3.txt a4.txt a5.txt a6.txt a7.txt a8.txt a9.txt a10.txt

$ ./add_zero.sh 
Input Directory[/home/m-ando] : .
Target Directory is "."
Input Common Name: a
Common Name is "a"
Input Target Extension: txt
Target Extension is "txt"
*** Successful.

$ ls
a001.txt a002.txt a003.txt a004.txt a005.txt a006.txt a007.txt a008.txt a009.txt a.010.txt