离开菜单时如何恢复"default on/offs"清单?



是否有简单的方法返回检查表的值?

像进入菜单(下面)选择"快","湖"one_answers"车",这样一切都是"打开"的。离开菜单,下次重新进入菜单时,会恢复相同的选择吗?

#! /bin/bash
dialog          --checklist "package timing" 20 75 5 
                        "tree" "4 MB" on 
                        "dog" "2 MB" on 
                        "fast" "5 MB" off 
                        "lake" "2 MB" off 
                        "car" "3 MB" off 2> ./tmp.$$

为了恢复选择,我们只需要从它们保存到的文件中读取它们(在您的示例中是tmp.$$),并将on插入dialog命令中的适当位置。可以使用关联数组。

#! /bin/bash
declare -A status=([dog]=on [tree]=on)  # initialize "tree" and "dog" to be on
while
    dialog --checklist "package timing" 20 75 5 
                       "tree" "4 MB" "${status[tree]}" 
                       "dog"  "2 MB" "${status[dog]}"  
                       "fast" "5 MB" "${status[fast]}" 
                       "lake" "2 MB" "${status[lake]}" 
                       "car"  "3 MB" "${status[car]}"  2>tmp.$$
do  : whatever you want
    set -- $(<tmp.$$); set -- ${@/#/[}; set -- ${@/%/]=on}
    eval declare -A status=($@)
done
rm tmp.$$

相关内容

  • 没有找到相关文章

最新更新