注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

独木人生

感悟生命

 
 
 

日志

 
 

dialog使用笔记(3)  

2007-08-23 21:20:21|  分类: Linux |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
1、man中的说明:

       --checklist text height width list-height [ tag item status ] ...
              A  checklist  box is similar to a menu box; there are multiple en-
              tries presented in the form of a menu.  Instead  of  choosing  one
              entry among the entries, each entry can be turned on or off by the
              user.  The initial on/off state of each entry is specified by sta-
              tus.

              On  exit,  a  list  of  the  tag strings of those entries that are
              turned on will be printed on dialog's output.  If the "--separate-
              output" option is not given, the strings will be quoted to make it
              simple for scripts to separate them.   See  the  "--single-quoted"
              option, which modifies the quoting behavior.
              
              
使用方法:dialog --checklist 文字 高度 宽度 列表高度 [ 标签1 内容1 状态1 ] [ 标签2 内容2 状态2 ] ...

2、示例源代码

#! /bin/sh
# $Id: checklist,v 1.8 2004/12/20 00:14:24 tom Exp $
: ${DIALOG=dialog}

: ${DIALOG_OK=0}
: ${DIALOG_CANCEL=1}
: ${DIALOG_ESC=255}

tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15

$DIALOG --backtitle "No Such Organization" \
        --title "CHECKLIST BOX" \
        --checklist "Hi, this is a checklist box. You can use this to \n\
present a list of choices which can be turned on or \n\
off. If there are more items than can fit on the \n\
screen, the list will be scrolled. You can use the \n\
UP/DOWN arrow keys, the first letter of the choice as a \n\
hot key, or the number keys 1-9 to choose an option. \n\
Press SPACE to toggle an option on/off. \n\n\
  Which of the following are fruits?" 20 61 5 \
        "Apple"  "It's an apple." off \
        "Dog"    "No, that's not my dog." ON \
        "Orange" "Yeah, that's juicy." off \
        "Chicken"    "Normally not a pet." off \
        "Cat"    "No, never put a dog and a cat together!" oN \
        "Fish"   "Cats like fish." On \
        "Lemon"  "You know how it tastes." on 2> $tempfile
retval=$?

choice=`cat $tempfile`
case $retval in
  $DIALOG_OK)
    echo "'$choice' chosen.";;
  $DIALOG_CANCEL)
    echo "Cancel pressed.";;
  $DIALOG_ESC)
    echo "ESC pressed.";;
  *)
    echo "Unexpected return code: $retval (ok would be $DIALOG_OK)";;
esac


3、分析

: ${DIALOG_OK=0} --- 作用是对返回值赋以有意义的名称

tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
--- 如果"tempfile"命令执行成功,则使用其结果作为临时文件名称;
否则,使用指定的名称,$$会被扩展为PID。
  评论这张
 
阅读(122)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017