0

I am using the below code to present users with a menu for them to select which software they would like to install. I then want to use the selections as function calls to perform the installs.

OPTIONS=$(dialog --no-tags --clear --backtitle "Installer Options..." --title "Software Selection" \
    --checklist "Use SPACE to select/deselct options and OK when finished."  30 100 30 \
       install_software_a "Install software A" off \
       install_software_b "Install software B" off \
       install_software_c "Install software C" off 2>&1 > /dev/tty)
$OPTIONS

The code works well for capturing the selections. The issue that I am having is that it writes the selections onto a single line, like below if the first two are selected:

install_software_a install_software_b

When the call is made to $OPTIONS, it is only installing the first software selected. Is there a way I can format the OPTIONS variable to have the selections written on separate lines like below:

install_software_a
install_software_b

TIA!

John

John O
  • 1

3 Answers3

1

If you have an awk version which supports multi-character record separators (should work on most recent implementations of awk), you can use the following call to transpose the data:

echo "$options" | awk -v RS="[ \n]" '1'
AdminBee
  • 22,803
1

You can redirect the output to a file, using the option --stdout, and then cat the file:

dialog --stdout --no-tags --clear --backtitle "Installer Options..." --title "Software Selection" \
    --checklist "Use SPACE to select/deselct options and OK when finished."  30 100 30 \
       install_software_a "Install software A" off \
       install_software_b "Install software B" off \
       install_software_c "Install software C" off \
 > file

OPTIONS=$(cat file | tr -s ' ' '\n')

echo "${OPTIONS[@]}"

install_software_a install_software_b

1

Use the --separate-output option of dialog (i.e., before the --checklist option). In the manual page:

--separate-output
For certain widgets (buildlist, checklist, treeview), output result one line at a time, with no quoting. This facilitates parsing by another program.

Thomas Dickey
  • 76,765