转自:交互式shell脚本对话框----whiptail指令
当你在linux环境下setup软件的时候就会有相应的对话框让你输入。虽然我们已经习惯了这种交互的方法,但是如果有一种直观的界面来输入是不是会更加友好和方便呢,在shell脚本中你可以使用-whiptail指令来完成。
消息框
语法:
1
|
whiptail
-
-
title
"<message box title>"
-
-
msgbox
"<text to show>"
<height> <width>
|
实例:
1
|
whiptail
-
-
title
"Message box title"
-
-
msgbox
" Choose Ok to continue."
10
60
|
yes/no对话框
语法:
1
|
whiptail
-
-
title
"<dialog box title>"
-
-
yesno
"<text to show>"
<height> <width>
|
实例:
1
2
3
4
5
6
|
#!/bin/bash
if
(whiptail
-
-
title
"Yes/No Box"
-
-
yesno
"Choose between Yes and No."
10
60
) then
echo
"You chose Yes. Exit status was $?."
else
echo
"You chose No. Exit status was $?."
fi
|
或者也可以是自定义的选项,实例如下:
1
2
3
4
5
6
|
#!/bin/bash
if
(whiptail
-
-
title
"Yes/No Box"
-
-
yes
-
button
"Man"
-
-
no
-
button
"Woman"
-
-
yesno
"What is your gender?"
10
60
) then
|