|
楼主 |
发表于 2004-9-14 19:00:41
|
显示全部楼层
不错不错,在文件开始处再加入下面的一个判断:
if [ $# -ne 1 ] ;then
echo "Usage: `basename $0` <filename >"
exit 1
fi
这样就更完美了。
感谢你的建议!
我以做了一些修正,主要是我实际碰到的一些问题。能够识别目录以及文件名有空格的情况,以及一些小的完善。
- #!/bin/sh
- #
- #AAE - Automated Archive Extractor - v$1.0
- #Date: 09-09-2004
- #
- #
- #This program can automated extracted all kinds of archive.
- if [ $# -ne 1 ] ;then
- echo ""
- echo "Usage: $0 <filename>"
- exit 1
- fi
- BASENAME=$(basename "$1")
- case ${1##*.} in
- tar)
- tar xvf "$1"
- ;;
- gz|z|Z)
- if [[ "${1:$((-6)):6}" == "tar.gz" || "${1:$((-5)):5}" == "tar.Z" ]]
- then
- tar xvfz "$1"
- else
- zcat "$1" > "${BASENAME%.*}"
- fi
- ;;
- bz2|bz)
- if [[ "${1:$((-7)):7}" == "tar.bz2" || "${1:$((-6)):6}" == "tar.bz" ]]
- then
- tar xvfj "$1"
- else
- bzcat "$1" > "${BASENAME%.*}"
- fi
- ;;
- tgz|taz)
- tar xvfz "$1"
- ;;
- tbz|tbz2)
- tar xvfj "$1"
- ;;
- zip|jar)
- mkdir -p "${BASENAME%.*}"
- unzip "$1" -d "${BASENAME%.*}"
- ;;
- rar)
- mkdir -p "${BASENAME%.*}"
- unrar x "$1" "${BASENAME%.*}"
- ;;
- *)
- echo "error: Sorry!I can't extract this Archive!"
- exit 1
- ;;
- esac
复制代码 |
|