4.密码框
格式:
dialog –passwordbox text height width [init]
例子:
1
2
# dialog –title "Password" –passwordbox \
"Please give a password for the new user:"
10
35
这样我们的密码就暴露出来了,是不是很不安全,所以通常我们会加上一个安全选项
–insecure 将每个字符用*来显示出来
1
2
# dialog –title "Password" –insecure \
—
passwordbox
"Please give a password for the new user:"
10
30
5.文本框
格式:dialog –textbox file height width
例子:
1
#dialog –title "The fstab" –textbox /etc/fstab 17 40
6.菜单框
格式:dialog –menu text height width menu-height tag1 item1 tag2 item2 …
例子:
1
2
#dialog –title "Pick a choice" –menu "Choose one" 12 35 5 \
1
"say hello to everyone"
2
"thanks for your support"
3
"exit"
7.Fselect框(文件选框)
格式:dialog –fselect filepath height width
例子:
1
#dialog –title "Pick one file" –fselect /root/ 7 40
8.复选框格式:dialog –checklist "Test" height width menu-height tag1 item1 tag2 item2 … 例子:
1
2
# dialog –backtitle "Checklist" –checklist "Test" 20 50 10 \
Memory
Memory
_Size
1
Dsik
Disk
_Size
2
<
b
>
<
/
b
>
9.显示日历格式:dialog –calendar "Date" height width day month year例子:#显示当前日期
1
# dialog –title "Calendar" –calendar "Date" 5 50
#显示指定日期
1
# dialog –title "Calendar" –calendar "Date" 5 50 1 2 2013
10.进度框架
格式:dialog –gauge text height width []
例子:
#固定进度显示
1
#dialog –title "installation pro" –gauge "installation" 10 30 10
#实时动度进度
1
2
#for i in {1..100} ;do echo $i;done | dialog –title \
"installation pro"
—
gauge
"installation"
10
30
#编辑到脚本中
编辑一个gauge.sh 的脚本
内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
# vim gauge.sh
declare
–
i
PERCENT
=
0
(
for
I
in
/
etc
/
*
;
do
if
[
$
PERCENT
–
le
100
]
;
then
cp
–
r
$
I
/
tmp
/
test
2
>
/
dev
/
null
echo
"XXX"
echo
"Copy the file $I …"
echo
"XXX"
echo
$
PERCENT
fi
let
PERCENT
+=
1
sleep
0.1
done
)
|
dialog
—
title
"coping"
—
gauge
"starting to copy files…"
6
50
0
#bash gauge.sh (执行脚本的时候注意修改权限)
11.from框架(表单)
格式:dialog –form text height width formheight [ label y x item y x flen ilen ] …
其中
flen 表示field length,定义了:选定字段中显示的长度
ilen 表示 input-length, 定义了:在外地输入的数据允许的长度
使用up/down(或ctrl/ N,ctrl/ P)在使用领域之间移动。使用tab键在窗口之间切换。
例子:
# dialog –title "Add a user" –form "Please input the infomation of new user:" 12 40 4 \
"Username:" 1 1 "" 1 15 15 0 \
"Full name:" 2 1 "" 2 15 15 0 \
"Home Dir:" 3 1 "" 3 15 15 0 \
"Shell:" 4 1 "" 4 15 15 0
综合应用示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
yesno
(
)
{
dialog
—
title
"First screen"
—
backtitle
"Test Program"
—
clear
—
yesno
\
"Start this test program or not ? \nThis decesion have to make by you. "
16
51
# yes is 0, no is 1 , esc is 255
result
=
$
?
if
[
$
result
–
eq
1
]
;
then
exit
1
;
elif
[
$
result
–
eq
255
]
;
then
exit
255
;
fi
username
}
username
(
)
{
cat
/
dev
/
null
>
/
tmp
/
test
.
username
dialog
—
title
"Second screen"
—
backtitle
"Test Program"
—
clear
—
inputbox
\
"Please input your username (default: hello) "
16
51
"hello"
2
>
/
tmp
/
test
.
username
result
=
$
?
if
[
$
result
–
eq
1
]
;
then
yesno
elif
[
$
result
–
eq
255
]
;
then
exit
255
;
fi
password
}
password
(
)
{
cat
/
dev
/
null
>
/
tmp
/
test
.
password
dialog
—
insecure
—
title
"Third screen"
—
backtitle
"Test Program"
—
clear
—
passwordbox
\
"Please input your password (default: 123456) "
16
51
"123456"
2
>
/
tmp
/
test
.
password
result
=
$
?
if
[
$
result
–
eq
1
]
;
then
username
elif
[
$
result
–
eq
255
]
;
then
exit
255
;
fi
occupation
}
occupation
(
)
{
cat
/
dev
/
null
>
/
tmp
/
test
.
occupation
dialog
—
title
"Forth screen"
—
backtitle
"Test Program"
—
clear
—
menu
\
"Please choose your occupation: (default: IT)"
16
51
3
\
IT
"The worst occupation"
\
CEO
"The best occupation"
\
Teacher
"Not the best or worst"
2
>
/
tmp
/
test
.
occupation
result
=
$
?
if
[
$
result
–
eq
1
]
;
then
password
elif
[
$
result
–
eq
255
]
;
then
exit
255
;
fi
finish
}
finish
(
)
{
dialog
—
title
"Fifth screen"
—
backtitle
"Test Program"
—
clear
—
msgbox
\
"Congratulations! The test program has finished!\n Username: $(cat /tmp/test.username)\n Password: $(cat /tmp/test.password)\n Occupation: $(cat /tmp/test.occupation)"
16
51
result
=
$
?
if
[
$
result
–
eq
1
]
;
then
occupation
elif
[
$
result
–
eq
255
]
;
then
exit
255
;
fi
}
yesno
本文转自:http://gdcsy.blog.163.com/blog/static/1273436092013016069255/
本站整理:http://www.ttlsa.com/html/3085.html