bash - 对话框命令 - "select all" 按钮
bash - dialog command - "select all" button
下面的link:
https://serverfault.com/questions/144939
它正确显示了如何使用“对话框”命令创建菜单,但未显示如何创建“select all”快捷按钮。
如何创建“Select 全部”按钮?
像这样:
#!/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
伊万,谢谢你。
从您的解决方案中汲取灵感,将其与 link:
的解决方案合并
https://serverfault.com/questions/144939
并以我自己的方式改进代码,我得到了这个解决方案:
#!/bin/bash
onoff=off
cmd=(dialog --output-fd 1 --separate-output --extra-button --extra-label "Select All" --cancel-label "Select None" --checklist "Select options:" 0 0 0)
load-dialog () {
options=(
1 "Option 1" $onoff
2 "Option 2" $onoff
3 "Option 3" $onoff
4 "Option 4" $onoff
)
choices=$("${cmd[@]}" "${options[@]}")
}
load-dialog
exit_code="$?"
while [[ $exit_code -ne 0 ]]; do
case $exit_code in
1) clear; onoff=off; load-dialog;;
3) clear; onoff=on; load-dialog;;
esac
exit_code="$?"
done
clear
for choice in $choices
do
case $choice in
1) echo "First Option";;
2) echo "Second Option";;
3) echo "Third Option";;
4) echo "Fourth Option";;
esac
done
sleep infinity
下面的link:
https://serverfault.com/questions/144939
它正确显示了如何使用“对话框”命令创建菜单,但未显示如何创建“select all”快捷按钮。
如何创建“Select 全部”按钮?
像这样:
#!/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
伊万,谢谢你。
从您的解决方案中汲取灵感,将其与 link:
的解决方案合并
https://serverfault.com/questions/144939
并以我自己的方式改进代码,我得到了这个解决方案:
#!/bin/bash
onoff=off
cmd=(dialog --output-fd 1 --separate-output --extra-button --extra-label "Select All" --cancel-label "Select None" --checklist "Select options:" 0 0 0)
load-dialog () {
options=(
1 "Option 1" $onoff
2 "Option 2" $onoff
3 "Option 3" $onoff
4 "Option 4" $onoff
)
choices=$("${cmd[@]}" "${options[@]}")
}
load-dialog
exit_code="$?"
while [[ $exit_code -ne 0 ]]; do
case $exit_code in
1) clear; onoff=off; load-dialog;;
3) clear; onoff=on; load-dialog;;
esac
exit_code="$?"
done
clear
for choice in $choices
do
case $choice in
1) echo "First Option";;
2) echo "Second Option";;
3) echo "Third Option";;
4) echo "Fourth Option";;
esac
done
sleep infinity