I'm trying to build a Zenity checklist from some arrays. My current approach is to loop over the arrays, build a string and pass it to Zenity, like this:
#!/bin/bash
column0=( "row 0" )
column1=( "row 0" )
column0+=( "row 1" )
column1+=( "row 1")
column0+=( "row 2" )
column1+=( "row 2" )
table=''
for (( i=0; i<${#column0[@]}; i++ ))
do
table="$table TRUE \"${column0[$i]}\" \"${column1[$i]}\""
done
echo $table
zenity --list --checklist --width=600 --height=450 \
--column="column 0" \
--column="column 1" \
--column="column 2" \
$table
The thing is, this is not working and the checklist is all broken, despite the echo sentence yields a correct string. Is there any issue in how I pass the string to Zenity?
table
needs to be an array for the same reason you made column0
and column1
arrays: to protect whitespace that is part of each element.
column0=( "row 0" "row 1" "row 2")
column1=( "row 0" "row 1" "row 2")
table=()
for (( i=0; i<${#column0[@]}; i++ ))
do
table+=(TRUE "${column0[$i]}" "${column1[$i]}")
done
zenity --list --checklist --width=600 --height=450 \
--column="column 0" \
--column="column 1" \
--column="column 2" \
"${table[@]}"