アーカイブを展開する

#!/bin/sh
#expansion_archive.sh

. f_askstring.sh

while : ; do
    ask_string "Input archive file name(.tgz or bz2): " 0
    if [ ! -f "$_STR" ]; then
        echo "Archive \"${_STR}\" not found."
        continue
    fi

    if [ "$_STR" != "${_STR%.tgz}" ]; then
        ARCHKIND=1
        break
    elif [ "$_STR" != "${_STR%.tar.bz2}" ]; then
        ARCHKIND=2
        break
    fi
done
ARCHNAME=$_STR

case $ARCHKIND in
    1) tar -xvzf ${ARCHNAME} ;;
    2) tar -xvjf ${ARCHNAME} ;;
esac

unset ARCHNAME ARCHKIND _STR
$ ls
1.tar.bz2 1.tgz 
$ ./expansion_archive.sh 
Input archive file name(.tgz or bz2): 1.tgz
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

$ ls 1
a001.txt  a003.txt  a005.txt  a007.txt  a009.txt
a002.txt  a004.txt  a006.txt  a008.txt  a010.txt