您的位置:首页 > 运维架构 > Linux

dialog几个常见的对话框

2010-02-26 00:33 381 查看
dialog
常见的对话框
--backtitle “ “ 背景文字
--title “ “ 定义文本框前的文字
--colors 给显示字体添加颜色
--defaultno 定义默认值为no
--stout 定义到标准输出
--insecure 和—passwordbox 一起使用 让输入的密码以*号显示,默认为不显示
--begin x y 定义对话框的显示位置

下面介绍几种常见的dialog对话框
1. --yesno “ ” 对话框高 对话框宽
显示一个对话框,提示用户选择yes 或者no,默认选择yes 选择后使用echo $? 发现选择默认为0 相反为1
[root@station40 ~]# dialog --backtitle "for example" --title "hello" --yesno "doyou want copy this file" 8 20
背景文字为 for example 对话框头部显示 hello 提供yes no 供选择
[root@station40 ~]# dialog --colors --backtitle "\Z1for example\Zn" --title "hello" --yesno "\Z2doyou want copy this file\Zn" 8 20
为文字添加颜色,注意—colors的格式 在\Z后面添加颜色数字,共有1到7种颜色,最后在文字最后以\Zn结尾
[root@station40 ~]# dialog --defaultno --colors --backtitle "\Z1for example\Zn" --title "hello" --yesno "\Z2doyou want copy this file\Zn" 8 20
使用—defaultno 更改默认值,使对话框出来时蓝色光标在no选项上
但是注意,在更改完之后,使用echo $?查看结果是仍是1
[root@station40 ~]# dialog --begin 10 15 --defaultno --colors --backtitle "\Z1for example\Zn" --title "hello" --yesno "\Z2doyou want copy this file\Zn" 8 20
--begin 是更改对话框的显示位置的,我们可以使用begin让它显示在我们希望的位置
2. --inputbox ""对话框高 对话框宽
 提供一个可输入信息的对话框,可追加文件
dialog --colors --backtitle "\Z1for example\Zn" --title "hello" --inputbox "please enter your name.." 12 20
nihao[root@station40 ~]# dialog --colors --backtitle "\Z1for example\Zn" --title "hellonputbox "please enter your name.." 12 20 2>/root/text.txt
将输入信息追加文件里,dialog默认为错误输出
3.—msgbox “ “ 对话框高 对话框宽
显示一个对话框,显示一句话
[root@station40 ~]# dialog --colors --backtitle "\Z1for example\Zn" --title "hello" --msgbox "OK" 8 15
4.—mauge 高 宽
使用管道符把前面的数字传送到dialog 以百分数显示传输过程,最后一位为百分比

[root@station40 ~]# (PERCENT=0;while [ $PERCENT -lt 100 ];do PERCENT=$[ $PERCENT+1] ;echo $PERCENT; done )|dialog --title "GAUGE WORKING" --gauge "working" 13 20 0
5. –menu “ “ 对话框高 对话框宽 菜单高 N1 “ “ N2 “ “ N3 “ “
[root@station40 ~]# dialog --backtitle "for example" --title "hello" --menu "please have a choice" 12 25 7 a "cat /etc/passwd" b "cat /etc/group" c "cat /etc/shadow"
提供一个对话框,可以使用上下框选择
6. –form “ ”对话框高 对话框宽 文本行数 “提示语“ 行数 列数 “默认字” 输入字符行数 字符列 可输入字符数 0 (0 指是否限制输入的字符,如果是2的话就是指只能输入两个字符)
[root@station40 ~]# dialog --backtitle "for example" --title "hello" --form "input field" 15 28 3 "name:" 1 2 "natasha" 1 13 13 2 "school:" 2 2 "" 2 13 13 0 " address:" 3 2 "" 3 13 13 0
7 –passwordbox “ ” 高 宽
dialog --title "hello" --passwordbox "please" 12 20
密码输入框 加上—insecure 以**显示
dialog --title "hello" --insecure --passwordbox "please" 12 20
8. –fselect “ ”文件路径 高 宽
显示一个目录中的文件及目录,可以选择
[root@station40 ~]# dialog --backtitle "for example" --title "hello" --fselect /etc/yum.repos.d 12 25
9.—textbox 文件路径 高 宽
显示一个文件内的内容
[root@station40 ~]# dialog --backtitle "for example" --title "hello" --textbox //etc/sysconfig/network 12 25
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 职场 休闲 dialog