详解Linux交互式shell脚本中创建对话框实例教程
详解Linux交互式shell脚本中创建对话框实例教程
本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下。
当你在终端环境下安装新的软件时,你可以经常看到信息对话框弹出,需要你的输入。对话框的类型有密码箱,检查表,菜单,等等。他们可以引导你以一种直观的方式输入必要的信息,使用这样的用户友好的对话框的好处是显而易见的。
当你写一个交互式shell脚本,你可以使用这样的对话框来接受用户的输入。whiptail可以在shell脚本中创建基于终端的对话框,消息框的过程,类似于Zenity或xdialog GUI脚本代码。预先安装在所有的Linux发布版本中。
下面来看看whiptail的用法:
创建一个消息框
一个消息框中显示一个确认按钮继续任意的文本消息。
语法:
whiptail –title “” –msgbox “”
实例:
#!/bin/bash
whiptail --title "Test Message Box" --msgbox "Create a message box with whiptail. Choose Ok to continue." 10 60
shell
创建一个yes/no对话框
用户输入yes或no的对话框。
语法:
whiptail –title “” –yesno “”
实例:
!/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
shell
或者,你可以是“–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) thenecho "You chose Skittles Exit status was $?."
elseecho "You chose M&M's. Exit status was $?."
fi
创建一个表单输入框
如果你想用户输入任意的文本,您可以使用一个输入框。
语法:
whiptail –title “” –inputbox “”
实例:
#!/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 ]; thenecho "Your pet name is:" $PET
elseecho "You chose Cancel."
fi
创建一个密码框
当用户需要输入敏感信息时密码框是有用的。
语法:
whiptail –title “” –passwordbox “”
实例:
#!/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 ]; thenecho "Your password is:" $PASSWORD
elseecho "You chose Cancel."
fi
创建一个菜单栏
当你想让用户选择一个任意数量的选择中,你可以使用菜单框。
#!/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 ]; thenecho "Your chosen option:" $OPTION
elseecho "You chose Cancel."
fi
创建radiolist对话框
语法:
whiptail –title “” –radiolist “” [ ] . . .
实例:
#!/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 ]; thenecho "The chosen distro is:" $DISTROS
elseecho "You chose Cancel."
fi
创建一个表对话框
当你想让用户选择一个列表中选择多个选项的清单对话框是有用的,radiolist对话框,只允许选择一个。
语法:
whiptail –title “” –checklist “” [ ] . . .
#!/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 ]; thenecho "Your favorite distros are:" $DISTROS
elseecho "You chose Cancel."
fi
创建一个进度条
进度条是一个用户友好的对话框。whiptail从标准输入读取一个百分数(0~100),显示一个表内相应的计数。
语法:
whiptail –gauge “”
实例:
#!/bin/bash
{for ((i = 0 ; i <= 100 ; i+=20)); dosleep 1echo $idone
} | whiptail --gauge "Please wait while installing" 6 60 0
详解Linux交互式shell脚本中创建对话框实例教程相关推荐
- 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器
本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...
- Linux shell 对话框,如何在 Bash Shell 脚本中显示对话框
原标题:如何在 Bash Shell 脚本中显示对话框 这个教程给出几个如何使用类似zenity和whiptail的工具在Bash Shell 脚本中提供消息/对话框的例子.使用这些工具,你的脚本能够 ...
- linux上传文件put,详解Linux ftp 命令行中下载文件get与上传文件put的操作方法
尽管现在有许多好的FTP应用程序,但服务器命令行ftp命令的应用程序仍然很多,下面就让电脑乐园小编带你一起来学习详解Linux ftp 命令行中下载文件get与上传文件put的操作方法. 介绍:从本地 ...
- linux shell spool,Linux/Unix shell 脚本中调用SQL,RMAN脚本
Linux/Unix shell脚本中调用或执行SQL,RMAN 等为自动化作业以及多次反复执行提供了极大的便利,因此通过Linux/Unix shell来完成Oracle的相关工作,也是DBA必不可 ...
- 【Linux】Shell脚本中如何使用“循环”遍历“数组”中的元素(包括MySQL的常用指令介绍)
一.背景 实习过程中,今天mentor突然让我拉取一下远端园区数据库中的部分信息,因为包含很多不同园区的数据信息,而且要以园区为单位生成文件来对数据进行存放,因此自然是需要使用shell脚本来自动生成 ...
- Linux系统Shell脚本中的echo命令
Linux系统Shell脚本中的echo命令 echo的作用 输出字符串 格式 echo "字符串内容" 一,显示转义字符 转义字符 ...
- Linux学习--Shell脚本的创建
Shell脚本的创建 [1]什么是shell shell它是命令行解析器,分为以下几类: (1)sh :(全称 Bourne Shell)是UNIX最初使用的 shell,而且在每种 UNIX 上都可 ...
- 【linux】Shell脚本中调用另外一个脚本的方法
在Linux平台上开发,经常会在console(控制台)上执行另外一个脚本文件,经常用的方法有:./my.sh 或 source my.sh 或 . my.sh:这三种方法有什么不同呢?我们先来了解一 ...
- 2021-10-26 linux 交互式shell脚本对话框----whiptail指令
一.编译Android kernel的时候弹出一个选择对话框,比较好奇,就认真分析了一下这个脚本对话框怎么来的. 1.编译的时候会调用mkimg文件. 2.mkimg文件里面会调用whiptail指令 ...
最新文章
- EXT2/EXT3/EXT4文件系统数据恢复工具开发计划
- Java 线程状态---WAITING(部分转载)
- assert函数_悉数Python函数传参的语法糖
- pytorch torch.tensor
- python 网络音乐播放器(二):tkinter 实现歌词同步滚动
- A Neural Algorithm of Artistic Style : Neural Style Transfer with Eager Executon
- Multisim函数发生器设置问题
- ansys 如何截取高清的网格图
- MATLAB与线性代数--简化阶梯矩阵
- JDK官方下载(旧版本,以前老版本)
- 解决No backends or directors found in VCL program, at least one is necessary. Runn
- WordPress如何添加canonical标签
- 深入理解光流法外推雷达回波
- 微信小程序-创建自己的小程序帐号
- 笔记本高分屏字体模糊_高分屏软件字体模糊的参考解决办法
- python 爬取腾讯漫画
- SpringBoot+Vue实现前后端分离的小而学在线考试系统
- css实现圆形进度条加载动画
- ‘vue-cli-service‘ is not recognized as an internal or external command
- 【医学图像处理】3 图像梯度及边缘提取