基于whiptail和shell脚本的交互式界面
官方使用手册 https://linux.die.net/man/1/whiptail
1. 使用背景
在linux环境下开发软件时,有时需要输入一连串的交互命令才能得到我们想要的数据或者结果,而每次我们都要重新输入这些指令,会比较繁琐。如果有一种直观的交互式界面工具来让用户输入关键信息,工具内部隐藏实现细节,是不是更方便、高效呢,本文描述一种在shell脚本中使用whiptail指令来编写交互式界面工具的方法。
2. whiptail指令介绍
2.1 什么是whiptail
linux man page 对whiltail的描述为:
whiptail is a program that will let you present a variety of questions or display messages using dialog boxes from a shell script。(大意为:whiptail是一个允许你使用shell脚本中的对话框呈现各种问题或显示消息的程序)。
2.2 whiptail常用语法
- 在linux终端下输入
whiptail
,可以看到如下输出:
Box options:
--msgbox <text> <height> <width>
--yesno <text> <height> <width>
--infobox <text> <height> <width>
--inputbox <text> <height> <width> [init]
--passwordbox <text> <height> <width> [init]
--textbox <file> <height> <width>
--menu <text> <height> <width> <listheight> [tag i