红联Linux门户
Linux帮助

Linux shell:dialog命令的使用

发布时间:2016-02-09 10:19:50来源:linux网站作者:樂天

下面这段代码来自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


运行:

Linux shell:dialog命令的使用

Linux shell:dialog命令的使用


分析: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。

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


本文永久更新地址:http://www.linuxdiyf.com/linux/17957.html