In order to restore the selections, we just have to read them from the file they were saved to (in your example tmp.$$
) and insert on
at the appropriate places in the dialog
command. We can use an associative array for that.
#! /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.$$