case :表达式可以用来匹配一个给定的字符串,而不是数字。
fi是if语句的结束,esac是case语句的结束。
case ... in
...) do something here ;;
esac
示例:
#!/bin/sh
ftype=`file "$1"`
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
运行:
smartzip articles.zip