30.4. whiptail - display dialog boxes from shell scripts

简介:

30.4.1. --msgbox

whiptail --title "Example Dialog" --msgbox "This is an example of a message box. You must hit OK to continue." 8 78
			
                                                               
 ┌─────────────────────────────┤ Example Dialog ├─────────────────────────────┐ 
 │                                                                            │ 
 │ This is an example of a message box. You must hit OK to continue.          │ 
 │                                                                            │ 
 │                                                                            │ 
 │                                   <Ok>                                     │ 
 │                                                                            │ 
 └────────────────────────────────────────────────────────────────────────────┘ 
                                                                                
			

30.4.2. --infobox

whiptail --title "Example Dialog" --infobox "This is an example of a message box. You must hit OK to continue." 8 78
			

30.4.3. --yesno

例 30.1. whiptail - yesno

#! /bin/bash
# http://archives.seul.org/seul/project/Feb-1998/msg00069.html
if (whiptail --title "PPP Configuration" --backtitle "Welcome to SEUL" --yesno "
Do you want to configure your PPP connection?"  10 40 )
then 
        echo -e "\nWell, you better get busy!\n"
elif    (whiptail --title "PPP Configuration" --backtitle "Welcome to
SEUL" --yesno "           Are you sure?" 7 40)
        then
                echo -e "\nGood, because I can't do that yet!\n"
        else
                echo -e "\nToo bad, I can't do that yet\n"
fi
				
whiptail --title "Example Dialog" --yesno "This is an example of a yes/no box." 8 78
 
exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "User selected Yes."
else
    echo "User selected No."
fi
 
echo "(Exit status was $exitstatus)"
				

设置--yes-button,--no-button,--ok-button 按钮的文本

whiptail --title "Example Dialog" --yesno "This is an example of a message box. You must hit OK to continue." 8 78 --no-button 取消 --yes-button 确认
			

30.4.4. --inputbox

例 30.2. whiptail - inputbox

result=$(tempfile) ; chmod go-rw $result
whiptail --inputbox "Enter some text" 10 30 2>$result
echo Result=$(cat $result)
rm $result
				
				
                         ┌────────────────────────────┐                         
                         │ Enter some text            │                         
                         │                            │                         
                         │ __________________________ │                         
                         │                            │                         
                         │                            │                         
                         │                            │                         
                         │    <Ok>        <Cancel>    │                         
                         │                            │                         
                         └────────────────────────────┘                         
				
				
				
COLOR=$(whiptail --inputbox "What is your favorite Color?" 8 78 --title "Example Dialog" 3>&1 1>&2 2>&3)
 
exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "User selected Ok and entered " $COLOR
else
    echo "User selected Cancel."
fi
 
echo "(Exit status was $exitstatus)"				
				
				

30.4.5. --passwordbox

例 30.3. whiptail - passwordbox

				
whiptail --title "Example Dialog" --passwordbox "This is an example of a password box. You must hit OK to continue." 8 78			
				
				

30.4.6. --textbox

例 30.4. whiptail - passwordbox

				
whiptail --title "Example Dialog" --textbox /etc/passwd 20 60
				
				

为文本取添加滚动条功能

whiptail --title "Example Dialog" --textbox /etc/passwd 20 60 --scrolltext
				

30.4.7. --checklist

例 30.5. whiptail - example 1

whiptail --title "Check list example" --checklist \
"Choose user's permissions" 20 78 16 \
"NET_OUTBOUND" "Allow connections to other hosts" ON \
"NET_INBOUND" "Allow connections from other hosts" OFF \
"LOCAL_MOUNT" "Allow mounting of local devices" OFF \
"REMOTE_MOUNT" "Allow mounting of remote devices" OFF
				

30.4.8. --radiolist

例 30.6. whiptail - radiolist

whiptail --title "Check list example" --radiolist \
"Choose user's permissions" 20 78 16 \
"NET_OUTBOUND" "Allow connections to other hosts" ON \
"NET_INBOUND" "Allow connections from other hosts" OFF \
"LOCAL_MOUNT" "Allow mounting of local devices" OFF \
"REMOTE_MOUNT" "Allow mounting of remote devices" OFF
				

30.4.9. --menu

			
whiptail --title "Menu example" --menu "Choose an option" 22 78 16 \
"<-- Back" "Return to the main menu." \
"Add User" "Add a user to the system." \
"Modify User" "Modify an existing user." \
"List Users" "List all users on the system." \
"Add Group" "Add a user group to the system." \
"Modify Group" "Modify a group and its list of members." \
"List Groups" "List all groups on the system."			
			
			
			
 ┌──────────────────────────────┤ Menu example ├──────────────────────────────┐ 
 │            <-- Back     Return to the main menu.                           │ 
 │            Add User     Add a user to the system.                          │ 
 │            Modify User  Modify an existing user.                           │ 
 │            List Users   List all users on the system.                      │ 
 │            Add Group    Add a user group to the system.                    │ 
 │            Modify Group Modify a group and its list of members.            │ 
 │            List Groups  List all groups on the system.                     │ 
 │                                                                            │ 
 │                                                                            │ 
 │                    <Ok>                        <Cancel>                    │ 
 │                                                                            │ 
 └────────────────────────────────────────────────────────────────────────────┘ 			
			
			

30.4.10. --gauge

			
#!/bin/bash
{
    for ((i = 0 ; i <= 100 ; i+=30)); do
        sleep 1
        echo $i
    done
} | whiptail --gauge "Please wait" 5 50 0	
			
		




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
Shell Perl
Shell之小tip (1)
Shell之小tip :1. 查看服务器的基本信息。2.后台运行任务。3. find的一些用法。4.文件压缩打包5.sed、grep、awk三剑客。
72 0
|
Linux Shell Windows
Shell - line 2: $‘\r‘: command not found
拷贝脚本提交后报错 line 2: $'\r': command not found,但是这是别的同学可以运行后发给我的,随后开始排查。安装 dos2unix 需要使用 yum。安装 yum 需要使用 brew。
500 0
Shell - line 2: $‘\r‘: command not found
AndroidStudio 设置显示行号(Show Line Numbers)
AndroidStudio 设置显示行号(Show Line Numbers)
339 0
AndroidStudio 设置显示行号(Show Line Numbers)