linux要求用case结构在终端下运行程序。在终端下运行程序,首先清屏,然后提示:“Input your age”。从键盘输入你的年龄(如:22),如果年龄在20-29,则输出“Please go to romm 101”,如果年龄在30-39之间,则输出“please go to room 201”;如果年龄在40-49之间,则输出“please go to room 301”;如果年龄在50-59之间,则输出“please go to room 401”;如果年龄在60-69之间,则输出“please go to room 501”;如果年龄不在上述范围,则输出“please wait at the door!”
时间: 2024-03-01 08:50:43 浏览: 40
好的,以下是实现该功能的 Bash 脚本:
```
#!/bin/bash
clear # 清屏
echo "Input your age:"
read age
case $age in
2[0-9]) echo "please go to room 101" ;;
3[0-9]) echo "please go to room 201" ;;
4[0-9]) echo "please go to room 301" ;;
5[0-9]) echo "please go to room 401" ;;
6[0-9]) echo "please go to room 501" ;;
*) echo "please wait at the door!" ;;
esac
```
这个脚本会提示用户输入年龄并读取输入的值,然后使用 `case` 结构进行判断。根据年龄的范围输出不同的提示信息,如果年龄不在范围内则输出默认信息。在脚本中使用 `clear` 命令清屏。
阅读全文
相关推荐
















