交互式shell脚本对话框----whiptail指令
当你在linux环境下setup软件的时候就会有相应的对话框让你输入。虽然我们已经习惯了这种交互的方法,但是如果有一种直观的界面来输入是不是会更加友好和方便呢,在shell脚本中你可以使用-whiptail指令来完成。
消息框

语法:
whiptail --title "<message box title>" --msgbox "<text to show>" <height> <width>
实例:
whiptail --title "Message box title" --msgbox " Choose Ok to continue." 10 60
yes/no对话框

语法:
whiptail --title "<dialog box title>" --yesno "<text to show>" <height> <width>
实例:
#!/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
或者也可以是自定义的选项,实例如下:

#!/bin/bash
if (whiptail --title "Yes/No Box" --yes-button "Man" --no-button "Woman" --yesno "What is your gender?" 10 60) then
echo "You chose Man Exit status was $?."
else
echo "You chose Woman. Exit status was $?."
fi
当选择左边选项的时候输出的是0,选择右边选项的时候输出的是1。
表单输入框

语法:
whiptail --title "<input box title>" --inputbox "<text to show>" <height> <width> <default-text>
实例:
#!/bin/bash
NAME=$(whiptail --title "Free-form Input Box" --inputbox "What is your pet's name?" 10 60 Peter 3>&1 1>&2 2>&3) exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "Your name is:" $NAME
else
echo "You chose Cancel."
fi
密码输入框

语法:
whiptail --title "<password box title>" --passwordbox "<text to show>" <height> <width>
实例:
#!/bin/bash
PASSWORD=$(whiptail --title "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 "Menu Dialog" --menu "Choose your favorite programming language." 15 60 4 \
"1" "Python" \
"2" "Java" \
"3" "C" \
"4" "PHP" 3>&1 1>&2 2>&3) exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "Your favorite programming language is:" $OPTION
else
echo "You chose Cancel."
fi
此处的选择输出的内容为你选择的标签的‘tag’位置,上面实例中的‘1’、‘2’、‘3’、‘4’
radiolist对话框
该对话框是单选对话框,你可以控制默认的选择位置,即使你在脚本中默认选择多个,他也只会输出一个结果
语法:
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 "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
参考链接:https://www.cnblogs.com/probemark/p/5890599.html
交互式shell脚本对话框----whiptail指令的更多相关文章
- Linux命令——whiptail交互式shell脚本对话框
转自:交互式shell脚本对话框----whiptail指令 当你在linux环境下setup软件的时候就会有相应的对话框让你输入.虽然我们已经习惯了这种交互的方法,但是如果有一种直观的界面来输入是不 ...
- 创建交互式shell脚本对话框
当你在终端环境下安装新的软件时,你可以经常看到信息对话框弹出,需要你的输入,比如:RHEL/CentOS自带的setup,对话框的类型有密码箱.检查表.菜单等等.他们可以引导你以一种直观的方式输入必要 ...
- 详解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脚本学习-1】
Shell学习笔记 简介: Shell 是一个用C语言编写的程序,它是用户使用Linux的桥梁.Shell既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个 ...
- Linux Shell脚本简单语法汇总(Deepin下运行)
整理自: https://www.runoob.com/?s=shell Shell 脚本(shell script),是一种为 shell 编写的脚本程序. 业界所说的 shell 通常都是指 sh ...
- shell脚本的使用该熟练起来了,你说呢?(篇四)
继续前一篇的文章: shell脚本的使用该熟练起来了,你说呢?(篇一) shell脚本的使用该熟练起来了,你说呢?(篇二) shell脚本的使用该熟练起来了,你说呢?(篇三) 文章里面测试的命令脚本文 ...
- Shell脚本编程入门到放弃
1 区分大小写 UNIX是区分大小写的,因此shell脚本也是区分大小写的 2 特殊字符 UNIX的某些字符都有特殊的意义或功能,如果它们不以其特殊的意义使用必须要进行转义(escaped). 为了转 ...
随机推荐
- LeetCode 561. Array Partition I (C++)
题目: Given an array of 2n integers, your task is to group these integers into npairs of integer, say ...
- Daily Scrum 11.15
今日完成任务: 1.在回答页面显示用户的相关信息 2.重写了搜索方法,并在自己的Demo网站测试成功 3.修改问题实体属性,加入悬赏积分:并在问题列表页面显示问题悬赏分数 遇到困难:一个是对于学长的搜 ...
- second scrum meeting - 151026
摘要:这一周的工作其实进行的并没有很迅速~不过我们团队的每个人都在慢慢进行自己的工作,并且我们也完成了大致的页面设计,开发了主页面的框架,并且我们也会开始着手学习服务器的操作,还有更加完善主页面的框架 ...
- 20172332 2017-2018-2 《程序设计与数据结构》Java哈夫曼编码实验--哈夫曼树的建立,编码与解码
20172332 2017-2018-2 <程序设计与数据结构>Java哈夫曼编码实验--哈夫曼树的建立,编码与解码 哈夫曼树 1.路径和路径长度 在一棵树中,从一个结点往下可以达到的孩子 ...
- WebGL学习笔记四点二
前几章对图形图形内部多是 以纯色填充,但是现实中已经有许多好的图片了我们没必要一点点画,这一章第五章就是将图片以纹理的形式加载到片元中,主要过程如下,首先是定义点的坐标的attribute变量用于在j ...
- 《[C#] int与System.Int32有什么区别》
最近园里的TeamOne写了一篇<[C#] int与System.Int32有什么区别>,发现里面有不少精彩的评论,所以忍不住想这篇文章总结一下:> 本文的主要参考资料: 1.< ...
- OTCL,面向对象的脚本一
Otcl 简介 面向对象的脚本语言 类变量和类方法 Otcl的基类称为Object(类的名字,不是面向对象中的"对象"),所以的Otcl类都是从Object派送来的. 直接贴代码, ...
- asp.net文件上传接收不到文件 Request.files["']等于null
这个时候你应该检查下你的form表单里面是否配置了这个: enctype ="multipart/form-data" 新手容易出错哦. <form id="fo ...
- Alpha 冲刺报告(4/10)
Alpha 冲刺报告(4/10) 队名:洛基小队 峻雄(组长) 已完成:继续行动脚本的编写 明日计划:尽量完成角色的移动 剩余任务:物品背包交互代码 困难:具体编码进展比较缓慢 ----------- ...
- Week2-作业1-part2.阅读与思考
第一章.概论 原文: 在成熟的航空工业中,一个飞机发动机从构思到最后运行,不知道经历过多少人.多少工序.多少流程.多少相关知识的验证.我们无法想象,某个商用型号的发动机在飞行时发现问题,最初的设计师会 ...