dialog widgets的选项,及使用方法
calendar  <text> <height> <width> <day> <month> <year>显示日历
checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...复选框
form      表单
editbox   <file> <height> <width>
dselect   <directory> <height> <width>
fselect   <filepath> <height> <width>文件选框,即平时上传本地文件时的那个
gauge     <text> <height> <width> [<percent>]进度条,百分之多少的那个
infobox   <text> <height> <width>弹出一个文本信息,不需要等待回应
inputbox  <text> <height> <width> [<init>]文本框
inputmenu <text> <height> <width> <menu height> <tag1> <item1>...可编辑菜单
menu      <text> <height> <width> <menu height> <tag1> <item1>...一个选择菜单
msgbox    <text> <height> <width>弹出一个文本信息,需要用户选择,并点击ok
pause     <text> <height> <width> <seconds>暂停页
passwordbox <text> <height> <width> [<init>]密码文本框,输入的任何内容显示为*
passwordform密码表单
progressbox <height> <width>
radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...单选按钮选框
tailbox   <file> <height> <width>显示tail命令类似内容
tailboxbg <file> <height> <width>加个背景的tailbox
textbox   <file> <height> <width>文本窗口,显示内容,如果一屏显示不了,可以滚动在整个窗口显示
timebox   <text> <height> <width> <hour> <minute> <second>选择时间的
yesno     <text> <height> <width>显示yes和no按钮
--backtitle 背景标题
--begin y x,用于指定窗口的位置,y为里上边缘的距离,x离左边缘的距离
--colors 使用\Z开始,\ZN结束框起来, 例:\Z(0-7颜色,b粗体,u下划线) .......\Zn
--defaultno 即yesno选项时,默认的按钮是在yes上还是no上
--default-item如果是个多选框,默认悬赏的
--insecure使用password时是否显示密码为*,默认是
--nocancel不显示cacel按钮
--nook不显示ok按钮
--no-shadow文本框是否有阴影,默认有,这样更有立体感
--ok-label默认label显示ok按钮
--timeout如果给出一个对话框,什么都不做的话,超时时间是多少 A=${A:-3}
--title标题

例:
显示一个普通的yesno

 
  
  1. dialog --backtitle "first" --title "first" --yesno "first" 15 60  


显示日历
 

 
  
  1. dialog --title "Calendar" --calendar "Date" 15 60 11 08 2012  

dialog --title "Calendar" --calendar "Date" 15 60显示当前日期
复选框(按空格选择,点击ok后,会在窗体下方输出信息,可以用--stdout将输出信息保存在变量中,供以后使用)
 

 
  
  1. dialog --backtitle "Checklist" --checklist "Test" 20 60 14 Memory Memory_Size 1 Dsik Disk_Size 2  

文件选框
 

 
  
  1. dialog --backtitle "Select a file" --fselect /etc/fstab 16 50  

选择菜单

 
  
  1. dialog --title "memory mon" --menu "statistics" 20 60 14 mem mem_statistics disk disk_statistics quit quit  


输入

 
  
  1. dialog --title "your name" --inputbox "name" 20 50  

密码框

 
  
  1. dialog --insecure --title "your name" --passwordbox "name" 20 50  


进度条

 
  
  1. dialog --title "installation pro" --gauge "installation" 10 30 10  


    动态样例进度条
 for I in {1..100} do sleep 1; echo $I;done | dialog --title "installation pro" --gauge "installation" 10 30
表单
 

 
  
  1. dialog --title "add a user" --form "please input the infomation of new user:" 12 40 4 \  
  2. "username:" 1 1 "" 1 15 15 0 \  
  3. "full name:" 2 1 "" 2 15 15 0 \  
  4. "home dir:" 3 1 "" 3 15 15 0 \  
  5. "shell:" 4 1 "" 4 15 15 0  

提醒一个用户删除文件 
 

 
  
  1. #!/bin/bash  
  2. #  
  3. TMP=`mktemp /tmp/test.XXXXXX`  
  4. echo "The temporory file $TMP" 
  5. dialog --backtitle "Delete file" --title "delete file $TMP" --yesno "Continue?" 7 30  
  6. RETVAL=$?  
  7. [ $RETVAL -eq 0 ] && rm -f $TMP || echo "Exit." 

提醒用户是查看memory还是disk或者退出
 

 
  
  1. #!/bin/bash  
  2. #  
  3. showmem() {  
  4. dialog --title "memory" --infobox "`free -m`" 20 60  
  5. }  
  6. showdisk() {  
  7. dialog --title "memory" --infobox "`df -hP`" 20 60  
  8. }  
  9. choice=`dialog --stdout --title "memory mon" --menu "statistics" 20 60 14 mem mem_statistics disk disk_statistics quit quit`  
  10. case $choice in 
  11. mem)  
  12. showmem ;;  
  13. disk)  
  14. showdisk ;;  
  15. quit)  
  16. exit ;;  
  17. esac  

复制文件动态进度条
 

 
  
  1. #!/bin/bash  
  2. #  
  3. declare -i PERCENT=0  
  4. (  
  5. for I in /etc/*;do  
  6.    if [ $PERCENT -le 100 ];then 
  7.      cp -r $I /tmp/test 2> /dev/null 
  8.      echo "XXX" 
  9.      echo "Copy the file $I ..." 
  10.      echo "XXX" 
  11.      echo $PERCENT  
  12.    fi  
  13.    let PERCENT+=1  
  14.    sleep 0.1  
  15. done ) | dialog --title "coping" --gauge "starting to copy files..." 6 50 0