当前位置:网站首页>Shell script -select in loop
Shell script -select in loop
2022-07-01 08:48:00 【Little snail's way】
select in yes Shell A unique cycle
Usage is as follows :
select variable in value_list
do
statements
done
variable Said variable ,value_list Indicates the value list ,in yes Shell Keywords in .
Code 1
#!/bin/bash
echo "What is your favourite OS?"
select name in "Linux" "Windows" "Mac OS" "UNIX" "Android"
do
echo "You have selected $name"
done
The running script is shown below :
What is your favourite OS?
1) Linux
2) Windows
3) Mac OS
4) UNIX
5) Android
#?
The input numbers are displayed as follows :
#? 3
You have selected Mac OS
#? 4
You have selected UNIX
#? 7
You have selected
#?
Input Ctrl+D Composite key , sign out
Be careful ,select It's infinite circulation ( Dead cycle ), Enter a null value , Or the value entered is invalid , Will not end the cycle , Only meet break sentence , Or press Ctrl+D Key combination can end the cycle .
Code 2:select in Usually and case in Use it together
#!/bin/bash
echo "What is your favourite OS?"
select name in "Linux" "Windows" "Mac OS" "UNIX" "Android"
do
case $name in
"Linux")
echo "Linux Is a class UNIX operating system , It's open source and free , Run on various server devices and embedded devices ."
break
;;
"Windows")
echo "Windows It's a personal computer operating system developed by Microsoft , It's closed source charging ."
break
;;
"Mac OS")
echo "Mac OS Apple is based on UNIX Developed a graphical interface operating system , It can only run on the hardware provided by Apple ."
break
;;
"UNIX")
echo "UNIX Is the founder of the operating system , Now it has gradually withdrawn from the stage of history , Only for special occasions ."
break
;;
"Android")
echo "Android By Google Developed mobile operating system , It has occupied 70% Market share ."
break
;;
*)
echo " Input error , Please re-enter "
esac
done
Output
Enter the correct option :
What is your favourite OS?
1) Linux
2) Windows
3) Mac OS
4) UNIX
5) Android
#? 2
Windows It's a personal computer operating system developed by Microsoft , It's closed source charging .
Input error options :
What is your favourite OS?
1) Linux
2) Windows
3) Mac OS
4) UNIX
5) Android
#? 7
Input error , Please re-enter
#? 4
UNIX Is the founder of the operating system , Now it has gradually withdrawn from the stage of history , Only for special occasions .
Enter a null value :
What is your favourite OS?
1) Linux
2) Windows
3) Mac OS
4) UNIX
5) Android
#?
1) Linux
2) Windows
3) Mac OS
4) UNIX
5) Android
#? 3
Mac OS Apple is based on UNIX Developed a graphical interface operating system , It can only run on the hardware provided by Apple .
边栏推荐
猜你喜欢

个人装修笔记

Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched

如何解决固定资产管理和盘点的难题?

嵌入式工程师面试题3-硬件

Vscode customize the color of each area

ARM v7的体系结构A、R、M区别,分别应用在什么领域?

MATLAB【函数求导】

Jeecg restart alarm 40001

Principle and application of single chip microcomputer - off chip development

内存大小端
随机推荐
DataBinding源码分析
Computer tips
如何解决固定资产管理和盘点的难题?
中考体育项目满分标准(深圳、安徽、湖北)
如何一站式高效管理固定资产?
易点易动助力企业设备高效管理,提升设备利用率
Serial port to WiFi module communication
电视机尺寸与观看距离
Nacos - 配置管理
Matlab [function derivation]
Promise异步编程
【C】 Summary of wrong questions in winter vacation
Redis——Lettuce连接redis集群
如何做好固定资产管理?易点易动提供智能化方案
Share 7 books I read in the first half of 2022
Insert mathematical formula in MD document and mathematical formula in typora
Common interview questions for embedded engineers 2-mcu_ STM32
Shell脚本-select in循环
Shell脚本-case in 和正则表达式
What is the material of 15CrMoR, mechanical properties and chemical analysis of 15CrMoR