[英]Menu Driven Shell Script bash
As a complete novice to this i am trying to make a Shell Script. 作为对此的完整新手,我正在尝试制作Shell脚本。 This will be driven by a menu with options such as delete file.
这将由带有选项(例如删除文件)的菜单驱动。 The part i am scuppered by is for example, when the menu is up, how to get from pressing '1', to actually creating a new file (as this is option 1 on my menu) I appreciate this may not be the easiest of questions to understand as my use of technical terms is limited, however i would appreciate any help.
例如,我被打扰的部分是,当菜单打开时,如何从按“ 1”到实际创建新文件(因为这是我菜单上的选项1),我知道这可能不是最简单的由于我对技术术语的使用受到限制,需要理解的问题非常多,但是我将不胜感激。 Below is an example of the first section of my menu.
以下是菜单第一部分的示例。 I feel once i know where to start i'll be fine
Menu
我觉得一旦我知道从哪里开始我将罚款
Menu
[1] Create File
[2] Delete File
[3] Rename file
Try doing this for example : 尝试这样做,例如:
select x in "Create File" "Delete File" "Rename file"; do
echo "$x choosen"
break
done
1) Create File
2) Delete File
3) Rename file
>
Search select
in the conditional construct paragraph here 在此处的条件构造段落中搜索
select
To run some specific tasks with the result of the $x
variable, you can use the case
statement (like switch
in other languages) like this : 要使用
$x
变量的结果运行某些特定任务,可以使用case
语句(例如其他语言的switch
),如下所示:
case $x in
Create*) touch file.txt ;;
Delete*) rm -f file.txt ;;
Rename*) mv file.txt file_old.txt ;;
esac
You can do it using switch/case statement. 您可以使用switch / case语句来实现。 Please have a look on the bash manual or look for similar examples on the Web.
请查看bash手册或在网上查找类似示例。 Just google "switch case shell example"
只是谷歌“开关箱壳的例子”
Good luck 祝好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.