在Bash case语句中,可以使用“*”通配符来匹配任何符号。下面是一个示例代码:
#!/bin/bash
echo "Please enter a character: "
read char
case $char in
a* )
echo "Input starts with 'a'"
;;
b* )
echo "Input starts with 'b'"
;;
* )
echo "Input does not start with 'a' or 'b'"
;;
esac
该脚本会提示用户输入一个字符,然后通过case语句来匹配输入的字符。如果输入以字母'a'开头,脚本会输出“Input starts with 'a'”,如果以字母'b'开头,脚本会输出“Input starts with 'b'”,否则输出“Input does not start with 'a' or 'b'”。