Linux命令——whiptail交互式shell脚本对话框

本文介绍了如何在Linux shell脚本中利用whiptail指令创建各种交互式对话框,包括消息框、yes/no对话框、表单输入框、密码输入框、菜单栏、radiolist对话框、多选对话框和进度条,以提供更友好的用户交互体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自:交互式shell脚本对话框----whiptail指令

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

消息框

语法:

1
whiptail  - - title  "<message box title>"  - - msgbox  "<text to show>"  <height> <width>

实例:

1
whiptail  - - title  "Message box title"  - - msgbox  " Choose Ok to continue."  10  60

 yes/no对话框

语法:

1
whiptail  - - title  "<dialog box title>"  - - yesno  "<text to show>"  <height> <width>

实例:

1
2
3
4
5
6
#!/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

或者也可以是自定义的选项,实例如下:

1
2
3
4
5
6
#!/bin/bash
if  (whiptail  - - title  "Yes/No Box"  - - yes - button  "Man"  - - no - button  "Woman"   - - yesno  "What is your gender?"  10  60 ) then
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值