LinuxQuestions.org
Review your favorite Linux distribution.
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 09-25-2006, 07:35 PM   #1
xlordt
Member
 
Registered: Dec 2003
Distribution: Slackware
Posts: 32

Rep: Reputation: 15
Bash Loop Dialog


Im wondering is this correct?

Im tring to add all the array values by looping it in to --menu, Im not that bright with dialogs yet... but would like some help on this. Also if it helps Im on slackware 10.1

Code:
menus=(
       [0]=First Menu [1]=Second Menu [2]=Thurd Menu
       [3]=Forth Menu [4]=Fith Menu   [5]=Six Menu
      )

COUNT=${#menus}

dialog --stdout \
       --title "Testing Loops" \
       --menu "This is the Menu" 15 55 5 \

for ((n=0; n <= $COUNT; n++))
do
  newvar=$"$n \"${menus[$n]}\""

  if [ ! $n = $COUNT ]; then
    newvar=$"$newvar \\"
  fi
  echo $newvar
done

Last edited by xlordt; 09-25-2006 at 07:41 PM.
 
Old 09-25-2006, 08:40 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Here is a site with some nice examples of dialog scripts which may give you some ideas...

http://metric.it.uab.edu/doc/linux/dialog-0.9a/samples/
 
Old 09-25-2006, 08:51 PM   #3
xlord
Member
 
Registered: Mar 2002
Posts: 75

Rep: Reputation: 15
Quote:
Originally Posted by homey
Here is a site with some nice examples of dialog scripts which may give you some ideas...

http://metric.it.uab.edu/doc/linux/dialog-0.9a/samples/
Thanx for the examples.. but I need some thing with loops in it :S
 
Old 09-25-2006, 11:28 PM   #4
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
OK first of all I really have no idea what you are trying to do. I just don't know what this means for sure: "Im tring to add all the array values by looping it in to --menu,"
Do you want to loop through each array element one at a time and run them through dialog? Or do you want to have all array elements displayed at once in a dialog menu?

First when you assign an array the "whitespace" is the default delimiter. You need to add some quotes to your array assignment like this:
Code:
menus=(
       [0]=First Menu [1]=Second Menu [2]=Thurd Menu
       [3]=Forth Menu [4]=Fith Menu   [5]=Six Menu
      )

s/b

menus=(
       "[0]=First Menu" "[1]=Second Menu" "[2]=Thurd Menu"
       "[3]=Forth Menu" "[4]=Fith Menu"   "[5]=Six Menu"
      )
Now a simple way to achieve what I think you want is like this:
All Menu Items on One Dialog:
Code:
#!/bin/bash
menus=(
       "[0]=First Menu" "[1]=Second Menu" "[2]=Thurd Menu"
       "[3]=Forth Menu" "[4]=Fith Menu"   "[5]=Six Menu"
      )
dialog --stdout \
       --title "Testing Loops" \
       --menu "This is the Menu" 15 55 6 ${menus[@]}
Each Menu Item on Dialog, one-at-a-time.
Code:
#!/bin/bash
menus=(
       "[0]=First Menu" "[1]=Second Menu" "[2]=Thurd Menu"
       "[3]=Forth Menu" "[4]=Fith Menu"   "[5]=Six Menu"
      )

COUNT=${#menus}

for ((n=0; n <= $COUNT; n++));do
  dialog --stdout \
         --title "Testing Loops" \
         --menu "This is the Menu" 15 55 5 ${menus[$n]}
done

Last edited by /bin/bash; 09-25-2006 at 11:37 PM.
 
Old 09-25-2006, 11:50 PM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
hello xlordt. can you post the expected output of your script?
 
Old 09-26-2006, 09:40 AM   #6
xlord
Member
 
Registered: Mar 2002
Posts: 75

Rep: Reputation: 15
Quote:
Originally Posted by konsolebox
hello xlordt. can you post the expected output of your script?
No need thanx what bin/bash did worked for me for now.. See what Im tring to do is create a menu with lots of submenu.. and I was wondering.. is it possiable to create a multy dimensional array? Also is it possiable to create class files in bash? Im still fairly new to bash so.. well I get what I want done.. I just never tried coding anything using classes in bash.

P.S: Hope it's understandable
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
bash while loop problem MadMusician_uk Programming 3 04-20-2006 11:52 AM
Dialog command not recognized on debian sarge's bash!!! CM019 Linux - Newbie 2 02-13-2005 03:37 PM
Bash for loop Genjix Programming 5 12-23-2004 02:56 AM
bash scripting: dialog --inputbox chibiace Linux - Newbie 1 11-08-2004 10:22 PM
Dynamic dialog in bash scripts AndiOliver Programming 3 04-22-2004 02:46 AM

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

All times are GMT -5. The time now is 04:23 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