创建交互式shell脚本对话框
当你在终端环境下安装新的软件时,你可以经常看到信息对话框弹出,需要你的输入,比如:RHEL/CentOS自带的setup,对话框的类型有密码箱、检查表、菜单等等。他们可以引导你以一种直观的方式输入必要的信息,使用这样的用户友好的对话框的好处是显而易见的。如下图所示:
当你写一个交互式shell脚本,你可以使用这样的对话框来接受用户的输入。whiptail可以在shell脚本中创建基于终端的对话框,消息框的过程,类似于Zenity或xdialog GUI脚本代码。whiptail预先安装在所有的Linux发布版本中。
语法:
whiptail --title "<message box title>" --msgbox "<text to show>" <height> <width>
实例:
#!/bin/bash whiptail --title "Test Message Box" --msgbox "Create a message box with whiptail. Choose Ok to continue." 10 60
语法:
whiptail --title "<dialog box title>" --yesno "<text to show>" <height> <width>
实例:
#!/bin/bash if (whiptail --title "Test 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
或者,你可以是“--yes-button” ,"--no-button"选项。
#!/bin/bash if (whiptail --title "Test Yes/No Box" --yes-button "Skittles" --no-button "M&M's" --yesno "Which do you like better?" 10 60) then echo "You chose Skittles Exit status was $?." else echo "You chose M&M's. Exit status was $?." fi
语法:
whiptail --title "<input box title>" --inputbox "<text to show>" <height> <width> <default-text>
实例:
#!/bin/bash PET=$(whiptail --title "Test Free-form Input Box" --inputbox "What is your pet's name?" 10 60 Wigglebutt 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then echo "Your pet name is:" $PET else echo "You chose Cancel." fi
语法:
whiptail --title "<password box title>" --passwordbox "<text to show>" <height> <width>
实例:
#!/bin/bash PASSWORD=$(whiptail --title "Test Password Box" --passwordbox "Enter your password and choose Ok to continue." 10 60 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then echo "Your password is:" $PASSWORD else echo "You chose Cancel." fi
语法:
whiptail --title "<menu title>" --menu "<text to show>" <height> <width> <menu height> [ <tag> <item> ] . . .
实例:
#!/bin/bash OPTION=$(whiptail --title "Test Menu Dialog" --menu "Choose your option" 15 60 4 \ "1" "Grilled Spicy Sausage" \ "2" "Grilled Halloumi Cheese" \ "3" "Charcoaled Chicken Wings" \ "4" "Fried Aubergine" 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then echo "Your chosen option:" $OPTION else echo "You chose Cancel." fi
语法:
whiptail --title "<radiolist title>" --radiolist "<text to show>" <height> <width> <list height> [ <tag> <item> <status> ] . . .
实例:
#!/bin/bash DISTROS=$(whiptail --title "Test Checklist Dialog" --radiolist \ "What is the Linux distro of your choice?" 15 60 4 \ "debian" "Venerable Debian" ON \ "ubuntu" "Popular Ubuntu" OFF \ "centos" "Stable CentOS" OFF \ "mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then echo "The chosen distro is:" $DISTROS else echo "You chose Cancel." fi
语法:
whiptail --title "<checklist title>" --checklist "<text to show>" <height> <width> <list height> [ <tag> <item> <status> ] . . .
实例:
#!/bin/bash DISTROS=$(whiptail --title "Test Checklist Dialog" --checklist \ "Choose preferred Linux distros" 15 60 4 \ "debian" "Venerable Debian" ON \ "ubuntu" "Popular Ubuntu" OFF \ "centos" "Stable CentOS" ON \ "mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then echo "Your favorite distros are:" $DISTROS else echo "You chose Cancel." fi
语法:
whiptail --gauge "<test to show>" <height> <width> <inital percent>
实例:
#!/bin/bash { for ((i = 0 ; i <= 100 ; i+=20)); do sleep 1 echo $i done } | whiptail --gauge "Please wait while installing" 6 60 0
本文转载自:http://www.linuxprobe.com/create-interactive-shell-script.html
更多Linux干货请访问:http://www.linuxprobe.com/
创建交互式shell脚本对话框的更多相关文章
- Linux命令——whiptail交互式shell脚本对话框
转自:交互式shell脚本对话框----whiptail指令 当你在linux环境下setup软件的时候就会有相应的对话框让你输入.虽然我们已经习惯了这种交互的方法,但是如果有一种直观的界面来输入是不 ...
- 交互式shell脚本对话框----whiptail指令
当你在linux环境下setup软件的时候就会有相应的对话框让你输入.虽然我们已经习惯了这种交互的方法,但是如果有一种直观的界面来输入是不是会更加友好和方便呢,在shell脚本中你可以使用-whipt ...
- 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器
本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...
- 交互式shell脚本web console
官网:http://web-console.org/ 这个脚本可以实现web下交互,也就是有了这玩意后可以不用反弹shell了. <?php // Web Console v0.9.7 (201 ...
- 非交互式shell脚本案例-实现自主从oracle数据库获取相关数据,并在制定目录生成相应规则的文件脚本
get_task_id 脚本内容 #!/usr/bin/expect#配置登陆数据库的端口set port 22#配置登陆数据库的ip地址set oracleip 10.0.4.41#配置数据库实例名 ...
- 创建和运行shell脚本程序
转载请标明http://www.cnblogs.com/winifred-tang94/ 要创建一个shell脚本程序,首先新建一个文本文件,然后在这个文本文件中按照shell编程规则输入shell命 ...
- 创建shell脚本文件
简单来说脚本就是将需要执行的命令保存到文本中,按照顺序(由上往下执行),它是解释型的,不需要 编译 脚本格式 #!/bin/bash或者#!/bin/env bash开头 第一个shell脚本:hel ...
- Shell脚本之九 输入输出重定向和文件包含
输出重定向:是指不使用系统提供的标准输入端口来输出,而是重新指定其他来进行输出.例如在终端输入的字符串本来是要输出到终端屏幕上的,但可以将输出指定为其他文件,将输入字符串输出到该文件中,而不再是屏幕上 ...
- Shell脚本 (一) 概述、解析器、脚本入门
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 一. Shell 脚本概述 1. Shell 的 含义: Shell 是一个用C语言编写的程序,它是用户 ...
随机推荐
- 1800: [Ahoi2009]fly 飞行棋
#include<cstdio> #include<iostream> using namespace std; ],n,ans; int main() { scanf(&qu ...
- C# Lodop实现打印
项目的Debug文件夹下有个template文件夹,里面有用到的js.自己建的要打印的网页和用到的背景图 1.打印方法: class print { public void printzb(strin ...
- RM报表预览,只有固定的1个订单页面
明明选了多个记录,预览时,只显示最后一个. 原因: 主项数据的数据集选了报表自带的虚拟数据集了.
- 10款最好用的MySQL数据库客户端图形界面管理工具
MySQL Workbench 该工具由MySQL开发,是一个跨平台的可视化数据库设计工具.它是DBDesigner4项目备受期待的替代者,它是一个本地图形化工具,支持的操作系统包括Windows.L ...
- iOS-生成国际化包-配置App多语言支持
标签: ios国际化 ios多语言支持 xcode多语言支持 xcode生成多语言 国际化 it 分类: 功能知识 如果你的App需要支持多国语言.那么,就应该为你的App应用添加“国际化”支 ...
- Fedora20的一些个人配置
0,老传统 yum install screenfetch 1,关闭蜂鸣器 edit /etc/bashrc setterm -blength 0#setterm -bfreq 10 #这个可以设置声 ...
- Maven 建立web项目 The import javax.servlet cannot be resolved
右击项目,选择Java Build Path->Libraries->Add External JARs,tomcat的路径lib文件夹下选中"servlet-api.jar&q ...
- 《JAVA笔记 day08 静态_单例》
//static关键字: /* 静态方法的使用注意事项: 1,静态方法不能访问非静态的成员. 但是非静态是可以访问静态成员的. 说明:静态的弊端在于访问出现了局限性.好处是可以直接别类名调用. 2,静 ...
- Mysql5.0以下 手工注入
order by 20 www. .com/product/introduction.php?id=-65 UNION SELECT user(),2 www. .com/product/introd ...
- android-volley-at-a-glance
http://liubin.org/2013/05/27/android-volley-at-a-glance/ http://www.androidhive.info/2014/05/android ...