我怎么能写一个bash脚本来显示一个菜单,接受用户输入和显示数据? [英] How can I write a Bash Script to display a menu, accept user input and display data?

查看:200
本文介绍了我怎么能写一个bash脚本来显示一个菜单,接受用户输入和显示数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写bash脚本用户输入我的任务被称为书店服务。首先,它有一个像增加新书名,作者姓名,删除书更新搜索秀书单,退出选项菜单。如果我选择选项1,我必须输入新书的名字。我怎么能写用户输入和显示输出数据时,我选择显示书籍列表选项。我有这个分配的麻烦。请别人帮我清楚这一点,那将是非常有益的,感谢大家。

I want to write Bash Script with User Input for my assignment called "book store service". Firstly, it has option menu like "add new book name " "author name" "remove book" "update" "search" "show book list" "Exit". If I choice option 1, I've got to input new book's name. How could I write the user input and display output data when I choice "show book list" option. I've got trouble with this Assignment. Pls someone help me to clear about this, that would be really helpful and thankful to all of you.

推荐答案

看看在选择语句。它允许你创建菜单。

Take a look at the select statement. It allows you to create a menu.

PS3="Please choose an option "
select option in go stay wait quit
do
    case $option in
        go) 
            echo "Going";;
        stay|wait) 
            echo "Standing by";;
        quit)
            break;;
     esac
done

这将是这样的:

1) go
2) stay
3) wait
4) quit
Please choose an option

编辑:

你的一个选择可能提示用户输入:

One of your options might prompt for user input:

read -rp "Enter a phrase: " phrase
echo "The phrase you entered was $phrase"

这篇关于我怎么能写一个bash脚本来显示一个菜单,接受用户输入和显示数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆