case"$OS"in FreeBSD) echo"This is FreeBSD" ;; Darwin) echo"This is Mac OSX" ;; AIX) echo"This is AIX" ;; Minix) echo"This is Minix" ;; Linux) echo"This is Linux" ;; *) echo"Failed to identify this OS" ;; esac
case$REPLYin [[:upper:]]) echo"'$REPLY' is upper case." ;;& [[:lower:]]) echo"'$REPLY' is lower case." ;;& [[:alpha:]]) echo"'$REPLY' is alphabetic." ;;& [[:digit:]]) echo"'$REPLY' is a digit." ;;& [[:graph:]]) echo"'$REPLY' is a visible character." ;;& [[:punct:]]) echo"'$REPLY' is a punctuation symbol." ;;& [[:space:]]) echo"'$REPLY' is a whitespace character." ;;& [[:xdigit:]]) echo"'$REPLY' is a hexadecimal digit." ;;& esac
执行上面的脚本,会得到下面的结果:
1 2 3 4 5 6
$ test.sh Type a character > a 'a' is lower case. 'a' is alphabetic. 'a' is a visible character. 'a' is a hexadecimal digit.