脚本可以自动解压bzip2, gzip和zip 类型的压缩文件:
#!/bin/sh
ftype=`file “$1″` # Note ‘ and ` is different
case “$ftype” in
“$1: Zip archive”*)
unzip “$1″ ;;
“$1: gzip compressed”*)
gunzip “$1″ ;;
“$1: bzip2 compressed”*)
bunzip2 “$1″ ;;
*) echo “File $1 can not be uncompressed with smartzip”;;
esac
你可能注意到上面使用了一个特殊变量$1,该变量包含有传递给该脚本的第一个参数值。也就是说,当我们运行:
smartzip articles.zip
$1 就是字符串 articles.zip。