当前位置:网站首页>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 .
边栏推荐
- 你了解数据是如何存储的吗?(C整型和浮点型两类)
- 【C】 Summary of wrong questions in winter vacation
- 分享2022上半年我读过的7本书
- TV size and viewing distance
- Shell脚本-read命令:读取从键盘输入的数据
- I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
- 基础:3.opencv快速入门图像和视频
- Software Engineer Interview Question brushing website and experience method
- 如何解决固定资产管理和盘点的难题?
- Principle and application of single chip microcomputer - off chip development
猜你喜欢

Bimianhongfu queren()

Brief introduction to AES

Insert mathematical formula in MD document and mathematical formula in typora

Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling

你了解数据是如何存储的吗?(C整型和浮点型两类)

It is designed with high bandwidth, which is almost processed into an open circuit?
![[MFC development (16)] tree control](/img/b9/1de4330c0bd186cfe062b02478c058.png)
[MFC development (16)] tree control

Qt的模型与视图

电视机尺寸与观看距离

19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
随机推荐
《微机原理》—总线及其形成
Guidelines and principles of did
TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
Personal decoration notes
[MFC development (17)] advanced list control list control
分享2022上半年我读过的7本书
MATLAB【函数和图像】
[untitled]
Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
Shell script - definition, assignment and deletion of variables
Properties of 15MnNiNbDR low temperature vessel steel, Wugang 15MnNiDR and 15MnNiNbDR steel plates
What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
毕业季,我想对你说
Graduation season, I want to tell you
Programming with C language: calculate with formula: e ≈ 1+1/1+ 1/2! …+ 1/n!, Accuracy is 10-6
【C】 Summary of wrong questions in winter vacation
【MFC开发(16)】树形控件Tree Control
The meaning of yolov5 training visualization index
Insert mathematical formula in MD document and mathematical formula in typora
《单片机原理与应用》——并行IO口原理