首页 > 解决方案 > bash - 对话框命令 - “全选”按钮

问题描述

下面的链接:
https
://serverfault.com/questions/144939 它正确显示了如何使用“对话框”命令创建菜单,但没有显示如何创建“全选”快捷按钮。
如何创建“全选”按钮?

标签: bashdialogubuntu-20.04

解决方案


像这样:

#!/bin/bash

onoff=off # all unset by defaul
dialog1(){ dialog --output-fd 1 --extra-button --extra-label "Select All" --checklist "Select options:" 0 0 0 "$@"; }
dialog2(){ choices=$(dialog1 "${options[@]}"); }

set_options(){ # make options array dynamic
    options=(
        1 "Option 1" $onoff
        2 "Option 2" $onoff
        3 "Option 3" $onoff
        4 "Option 4" $onoff
    )
}

set_option
dialog2

case $? in          # if 'Select All' presssed
     3) onoff=on    # set all to on
        set_options # reassemble options
        dialog2;;   # and run dialog again
esac

clear
echo $choices

推荐阅读