linux dialog 源码,Linux dialog详解(图形化shell)
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
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的linux dialog 源码,Linux dialog详解(图形化shell)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: h5前端 调用手机通讯录
- 下一篇: linux ftp配置chroot,vs