用于用户密码授权的 csh 脚本
我正在尝试编写一个专业程序来通过基于菜单的系统接受和处理输入。该程序不应有命令行参数。它将被写入名为 TaskMenu 的 csh 脚本中。此 shell 脚本将:
- 向用户询问密码。
一个。如果密码不正确,系统将退出 并带有适当的错误消息。 - 显示文本菜单,然后获取用户的响应。
- 处理用户输入并重新显示文本菜单 直到用户想要退出。
I'm trying to write a professional program to accept and process input via a Menu based system. The program should have no command line arguments. it will be writen in csh script called TaskMenu. This shell script will:
- ask for a password from the user.
a. If the password is not correct, the system will exit
with an appropriate error message. - display a text menu and then get a response from the user.
- process the user input and redisplay the text menu
until the user wants to quit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要读取密码,请关闭回显,读取密码,然后重新启用回显。 csh:
要创建菜单,只需将选项回显到屏幕上,然后
读回一个值。 csh:
bash 中的这两个相同的任务是:
读取密码:
创建菜单:
注意 bash 中如何内置读取密码和创建菜单。除了更容易之外,一些在脚本中完成的常见事情在 csh 中是不可能的。 Csh 并不是被设计为脚本语言。使用 Bash、Python、Ruby、Perl 甚至低级的 /bin/sh 来编写几行脚本要容易得多。
也就是说,这里是一个完整的 csh 脚本,显示了密码和菜单方法:
注释
1 维基百科
To read a password, turn echo off, read the password, then re-enable echo. csh:
To create a menu, just echo the choices to the screen, then
read a value back. csh:
These same two tasks in bash are:
Read password:
Make menu:
Notice how reading a password and making a menu are built-in to bash. In addition to being easier, some common things done in scripting are impossible in csh. Csh is not designed as a scripting language. It is much easier to use Bash, Python, Ruby, Perl or even the lowly /bin/sh for scripting anything over a few lines.
That said, here is a full csh script showing the password and menu methods:
Notes
1 Wikipedia
问:到底为什么有人想在 bash 世界中使用 csh ;) csh 是 Soooo 1985 ;)
Q: Why in the heck would anybody want to use csh in a bash world ;) csh is Soooo 1985 ;)