LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash: generating a string containing options and using with kdialog (https://www.linuxquestions.org/questions/programming-9/bash-generating-a-string-containing-options-and-using-with-kdialog-648873/)

arizonagroovejet 06-12-2008 01:26 PM

bash: generating a string containing options and using with kdialog
 
I'm writing a script where I want to present a list of options in a kdialog radiolist. The options are very similar so I want to generate them in a loop somehow then give them to kdialog. So far I have...
Code:

#!/bin/bash
EMPTY_AFTER_DAYS=1
dialogoptions="";
for i in `seq 1 7`;do
  status="off";
  if [ $i -eq $EMPTY_AFTER_DAYS ];then status="on";fi
  days="days";
  if [ $i -eq 1 ];then days="day";fi
  dialogoptions="$dialogoptions $i 'Automatically remove files from Wastebin after $i $days' $status"
done
echo $dialogoptions
set -x
kdialog --radiolist "Files in the Wastebin count towards your quota usage. Automatically removing files from the Wastebin helps you stay within your quota limit." $dialogoptions

The radio list options are all messed up when they're displayed though. The output I see from using 'set -x' is

Code:

1 'Automatically remove files from Wastebin after 1 day' on 2 'Automatically remove files from Wastebin after 2 days' off 3 'Automatically remove files from Wastebin after 3 days' off 4 'Automatically remove files from Wastebin after 4 days' off 5 'Automatically remove files from Wastebin after 5 days' off 6 'Automatically remove files from Wastebin after 6 days' off 7 'Automatically remove files from Wastebin after 7 days' off
+ kdialog --radiolist 'Files in the Wastebin count towards your quota usage. Automatically removing files from the Wastebin helps you stay within your quota limit.' 1 ''\''Automatically' remove files from Wastebin after 1 'day'\''' on 2 ''\''Automatically' remove files from Wastebin after 2 'days'\''' off 3 ''\''Automatically' remove files from Wastebin after 3 'days'\''' off 4 ''\''Automatically' remove files from Wastebin after 4 'days'\''' off 5 ''\''Automatically' remove files from Wastebin after 5 'days'\''' off 6 ''\''Automatically' remove files from Wastebin after 6 'days'\''' off 7 ''\''Automatically' remove files from Wastebin after 7 'days'\''' off

The quoting is clearly all screwed up when the variable is expanded for use with kdialog.

Can anyone explain how to get this to work? I've been mucking around with the quotes for about an hour and I'm completely stumped. Maybe

arizonagroovejet 06-12-2008 02:12 PM

Solved it myself after reading through some other threads on here. :)

Code:

eval kdialog --radiolist "'Files in the Wastebin count towards your quota usage. Automatically removing files from the Wastebin helps you stay within your quota limit.'" $dialogoptions
I must confess I'm not entirely certain why it works, but it does.


All times are GMT -5. The time now is 06:43 PM.