LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-29-2009, 02:31 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 49
looping an array to populate menu for "dialog"


Hi,

I have a array called "usb_device" which has 3 elements as follows:
Code:
/dev/sda
/dev/sdb
/dev/sdc
Now I am trying to display these elements with the 'dialog' utility like this:
Code:
dialog --clear --title "List USB Devices" \
       --menu "Move using [UP] [DOWN} Arrow keys, Hit [ENTER] key to select." 15 50 5 \
for (( i = 0; i < ${#get_usb_devices[@]}; i++ ))
do
$i $get_usb_devices \
done

exit 0
However when I try to run this I get following error:
Code:
./detect_usb.sh: line 10: syntax error near unexpected token `('
./detect_usb.sh: line 10: `for (( i = 0; i < ${#get_usb_devices[@]}; i++ ))'
Not sure what's going wrong here.
 
Old 01-29-2009, 03:28 PM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
I do not think this kind of construct is easily possible within Bash - in Common Lisp though, it would be quite simple, but that's besides the point.

I think you are going to have to work some magic with grep and awk (maybe sed, too) and wrap it in $() - see example. I would provide an example, but I have never used awk and/or sed before.

Example:
Code:
dialog --clear --title "List USB Devices" \
       --menu "Move using [UP] [DOWN} Arrow keys, Hit [ENTER] key to select." 15 50 5 \
       $(grep_awk_and_sed_magic)

Last edited by indienick; 01-29-2009 at 03:29 PM.
 
Old 01-30-2009, 12:54 AM   #3
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
I'm not entirely sure what you are trying to achieve, but it looks as if you want to add stuff to the command line of a program (dialog in this case). For that, you need xargs, unless you want to build the entire command line in advance, which is also possible.
 
Old 01-30-2009, 01:41 AM   #4
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by burschik View Post
I'm not entirely sure what you are trying to achieve, but it looks as if you want to add stuff to the command line of a program (dialog in this case). For that, you need xargs, unless you want to build the entire command line in advance, which is also possible.
What I am trying to is to just display a menu from my array - get_usb_devices. The utility dialog with --menu option expects two parameters for each item. Here is a simple example of using menu with dialog:
Code:
dialog --clear --title "List USB Devices" \
       --menu "Move using [UP] [DOWN} Arrow keys, Hit [ENTER] key to select." 15 50 5 \
1. "usb hard drive"
2. "usb flash drive"
3. "usb cd-rom"
Now instead of the above three items I would like to display the items from my array. Try running the above piece of code and you will see what I am trying to say.

Thanks
 
Old 01-30-2009, 02:20 AM   #5
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
So my assumption was correct. Use xargs.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
converting shell script from "dialog" to "xdialog" kushalkoolwal Programming 1 02-25-2008 08:40 PM
Lost "Shutdown" and "Restart" From system menu in FC6 Nader1 Linux - Software 3 02-12-2007 04:40 PM
[Shell] "looping" i/o redirection probabil1ty Programming 10 12-30-2006 10:44 AM
KDE "Logout" and "Lock Session" menu restoration powah Linux - Software 3 03-29-2005 08:02 PM
KDE "Lock Session" and "Logout" menu restoration tcma Linux - Software 0 01-29-2005 11:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration