Z="compress"; unZ="uncompress"; Zlist=""
gz="gzip" ungz="ungzip"; gzlist=""
bz="bzip2" unbz="bunzip2" bzlist=""
for arg do
if [ -f "$arg" ];then
case "$arg" in
*.Z) $unZ "$arg"
arg="$(echo $arg | sed 's/\.Z$//')"
Zlist="$ZList \"$arg\""
;;
*.gz) $ungz "$arg"
arg="$(echo $arg | sed 's/\.gz$//')"
gzlist="$gzList \"$arg\""
;;
*.bz2) $unbz "$arg"
arg="$(echo $arg | sed 's/\.bz2$//')"
bzlist="$bzlist\"$arg\""
;;
esac
fi
newargs="${newargs:-""} \"$args\""
done
case $0 in
*zcat*) eval cat $newargs ;;
*zmore*) eval more $newargs ;;
*zgrep*) eval grep $newargs ;;
*) echo "$0:unknown base name.Can't preceed.">&2
exit1
esac
if [ ! -z "$list" ];then
eval $Z $Zlist
fi
if [ ! -z "$gzlist" ];then
eval $gz $gzlist
fi
if [ ! -z "$bzlist" ];then
eval $bz $bzlist
fi
exit 0
运行结果