Search code examples
bashtextdialogwhiptail

Use dynamic list in whiptail


I need to build a dynamic list with checkboxes in whiptail. But using a variable\dynamic bash output doesn't help me.

I tryed used this command

whiptail --title "Operations" --checklist "Select Operation" 22 80 14 $array

Output of variable array is

"cash3" "54311 May 25 10:10 22A763D0-8203-11E9-39BE-0007321A6EB4" OFF "cash10" "10475 May 28 18:23 22A763D0-8203-11E9-82FE-0007321A6EB4" OFF "cash14" "9905 May 27 15:55 22A763D0-8203-11E9-86FD-0007321A6EB4" OFF "cash13" "11780 May 29 09:32 22A763D0-8203-11E9-66AD-0007321A6EB4" OFF

what fully corresponds to the whiptail syntax of the command, but this command is not executed.

When using the same data, but not through a variable whiptail works


Solution

  • You only use the first element with $array. You can make use of the entire array with ${array[@]}.

    This will work:

    #! /bin/bash
    
    array=("cash3" "54311 May 25 10:10 22A763D0-8203-11E9-39BE-0007321A6EB4" OFF "cash10" "10475 May 28 18:23 22A763D0-8203-11E9-82FE-0007321A6EB4" OFF "cash14" "9905 May 27 15:55 22A763D0-8203-11E9-86FD-0007321A6EB4" OFF "cash13" "11780 May 29 09:32 22A763D0-8203-11E9-66AD-0007321A6EB4" OFF)
    
    whiptail --title "Operations" --checklist "Select Operation" 22 80 14 "${array[@]}"
    

    Note that without quoting the array ("), whiptail will not work correctly.