アーカイブを作成し圧縮する

#!/bin/sh
#mk_arch.sh

. f_askdir.sh
. f_askstring.sh

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

ask_string "Input archive file name: " 0
ARCHNAME=$_STR
echo "Archive file Name is \"${ARCHNAME}\""

if [ "$ARCHNAME" != "${ARCHNAME%.tgz}" ]; then
    ARCHKIND=1
    ARCHNAME="${ARCHNAME%.tbz2}"
else
    echo " 1) gzip(.tgz)"
    echo " 2) bzip2(.tar.bz2)"
    echo -n " Select Number : "

    while read ANSWER ; do
        case "${ANSWER}" in
            1) ARCHKIND=1 ; break ;;
            2) ARCHKIND=2 ; break ;;
            *) echo "*** Menu not found." ;;
        esac
        echo -n " Select Number : "
    done
fi

case $ARCHKIND in
    1) tar -cvzf ${ARCHNAME}.tgz ${_DIRNAME} ;;
    2) tar -cvjf ${ARCHNAME}.tar.bz2 ${_DIRNAME} ;;
esac

echo "*** Successful."
unset _DIRNAME ARCHNAME ANSWER ARCKIND _STR
$ ls 1
a001.txt  a003.txt  a005.txt  a007.txt  a009.txt
a002.txt  a004.txt  a006.txt  a008.txt  a010.txt

$ ./mk_arch.sh 
Input Directory (Blank is Cancel.) : 1
Target directory is "1"
Input archive file name: 1
Archive file Name is "1"
 1) gzip(.tgz)
 2) bzip2(.tar.bz2)
 Select Number : 1
1/
1/a001.txt
1/a002.txt
1/a003.txt
1/a004.txt
1/a005.txt
1/a006.txt
1/a007.txt
1/a008.txt
1/a009.txt
1/a010.txt
*** Successful.

$ ls
1.tar.bz2 1.tgz