shell case 语句示例
时间: 2023-11-11 13:07:57 浏览: 206
详解shell脚本中的case条件语句介绍和使用案例
Sure, I can help with that! Here's an example of a shell case statement in Bash:
```bash
read -p "What is your favorite color? " color
case $color in
red)
echo "Red is a great color!"
;;
blue)
echo "Blue is also a nice color."
;;
green)
echo "Green is a good choice."
;;
*)
echo "Hmm, I'm not sure what color that is."
;;
esac
```
This script prompts the user for their favorite color, and then uses a case statement to choose a response based on their input. If the user enters "red", the script will output "Red is a great color!", and so on. The final `*)` case is the "default" case that will match anything that doesn't match the previous cases.
阅读全文