CentOS7.3学习笔记总结(七十五)

Dialog是一个程序,它允许你使用shell脚本中的对话框程序各种 或显示消息(这是帮助文档开头的一句话)。文本菜单已经很不错了,但是还是要在这里介绍一下窗口制作工具dialog,给以后的工作多一种选择。

CentOS linux系统中,默认是不安装dialog包的,安装方法也是非常简单的,直接yum安装就行,命令如下:

yum install dialog

image.png                                           

先来个Hello

在命令行中输入:

dialog --title Testing --msgbox "Hello,world!" 10 20

image.png

用鼠标点击确认,或者按下回车,则关闭对话框。这个就是msgbox部件,dialog有多个部件,介绍如下:

calendar:提供选择日期的日历

格式:dialog --calendar "Date" height width day month year

例:

显示当前日期:

dialog --title "日历查询" --calendar "Date" 5 50

image.png

显示指定日期:

dialog --title "日历查询" --calendar "Date" 5 50 1 2 2000

image.png

checklist:显示多个选项(其中每个选项都能打开或关闭),就是复选框

格式:dialog  --checklist "Test" height width  menu-height  tag1 item1 tag2 item2 …

例:

dialog --backtitle "Checklist" --checklist "check box" 20 50 10 TAG01 ITEM01 1 TAG02 ITEM02 2 TAG03 ITEM03 3

image.png

form:构建一个带有标签以及文本字段(可以填写内容)的表单

格式:dialog --form text height width formheight [ label y x item y x flen ilen ] ...

例:

dialog --title "添加用户" --form "输入用户信息:" 12 40 4    "用户名:" 1  1 "" 1  15  15  0    "姓名:" 2  1 "" 2  15  15  0    "家目录:" 3  1 "" 3  15  15  0    "Shell:"    4   1 "" 4  15  15  0

image.png

fselect:文件选框,提供一个文件选择窗口来浏览选择文件

格式:dialog --fselect filepath height width

例:

dialog --title "选择一个文件" --fselect /root/ 7 40

image.png

gauge:显示完成的百分比进度条

格式:dialog --gauge text height width  [<percent>]

例:

dialog --title "安装进度" --gauge "**软件安装中" 10 30 10

image.png

inputbox输入框,提供一个输入文本用的文本表单

格式:dialog --inputbox text height width

例:

dialog --title "输入文字"  --inputbox "请输入你的 内容:" 10 30#在后面加2>1.txt,内容就会写入到文件中

image.png

menu:显示可选择的一个列表选项

格式:dialog --menu text height width  menu-height tag1 item1 tag2 item2 …

例:

dialog --title "菜单框" --menu "请选择一个" 12 35 5 1 "菜单01" 2 "菜单02" 3 "exit"

image.png

msgbox:消息框,显示一条消息,并要求用户选择OK按钮

格式:dialog  - -msgbox  text   height  width

例:

dialog --title Testing --msgbox "Hello,world!" 10 20

passwordbox:显示一个文本框,但会隐藏输入的文本

格式:dialog  --passwordbox text height width [init]

例:

dialog --title "密码"  --passwordbox "请输入你的密码:" 10 35

dialog --title "密码" --insecure --passwordbox "请输入你的密码:" 10 35

--insecure参数后,输入密码时显示为*号,比较安全。

image.png

textbox:文本框,在滚动窗口中显示文件的内容

格式:dialog --textbox file height width

例:

dialog --title "The lxt.txt" --textbox /root/lxt.txt  17 40

image.png

infobox:显示一条消息,但不用等待回应

inputmenu:提供一个可编辑的菜单

pause:显示一个进度条来显示暂定期间的状态

passwordform:显示一个带标签和隐藏文本字段的表单

radiolist:单选框,提供一组菜单选项,但只能选择其中一个

tailbox:用tail命令在滚动窗口中显示文件的内容

tailboxbg:跟tailbox一样,但是在后台模式中运行

timebox:提供一个选择小时、分钟和秒数的窗口

yesno:提供一条带有YesNo按钮的简单消息

dialog命令选项:

image.png

这里只做了dialog的基本介绍,以后逐步深入介绍dialog的用法。请大家注意关注。


猜你喜欢

转载自blog.51cto.com/6300167/2543510