Linux shell:dialog命令的使用

下面这段代码来自http://unix.stackexchange.com/questions/67877/screen-buffer-and-dialog

#!/usr/bin/env bash
tput smcup
clear
dialog --yesno "Do you want to continue?" 0 0
rc=$?
clear
tput rmcup
if [ "${rc}" == "0" ]; then
  echo Yes
else
  echo No
fi

运行:

分析: tput smcup用来保存当前的display,tput rmcup用来恢复之前保存的display。

dialog命令用来显示对话框。--yesyno参数的解释如下:

       --yesno text height width
              A yes/no dialog box of size height rows by width columns will be
              displayed.  The string specified by text is displayed inside the
              dialog  box.   If this string is too long to fit in one line, it
              will be automatically divided into multiple lines at appropriate
              places.  The text string can also contain the sub-string "\n" or
              newline characters `\n' to  control  line  breaking  explicitly.
              This  dialog box is useful for asking questions that require the
              user to answer either yes or no.  The dialog box has a Yes  but‐
              ton  and  a  No  button, in which the user can switch between by
              pressing the TAB key.

              On exit, no text is written to dialog's output.  In addition  to
              the "Yes" and "No" exit codes (see DIAGNOSTICS) an ESC exit sta‐
              tus may be returned.

              The codes used for "Yes" and "No" match those used for "OK"  and
              "Cancel", internally no distinction is made.

若选择yes,退出码为0;选择no,则为非0。

$?是上一条命令的退出码。

转载于:https://my.oschina.net/letiantian/blog/527085

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值