Dialog menu with array

Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Dialog menu with array

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Hi

I'm currently making a schoolproject and I'm stuck with reading an array into the possible options of a menu dialog. What I mean is: I've put some values into an array, I want all these values from the array to be possible to be selected in the menu. I'm npot sure how many options should be available, so i use the array length. Please help Smilie
I'm programming in Debian and I use bash.

Thanks

variables:
array muzieklijst[]
mpg123 is for playing the song

2. Relevant commands, code, scripts, algorithms:

dialog --menu "title" width height optionsammount\
option1 \
option 2 \
option 3 \
...

3. The attempts at a solution (include all code and scripts):

Code:
dialog --menu "Choose song" 25 75 ${#muzieklijst[@]} \
        for j in $(`cat muzieklijst.txt`) ; do
            echo ""$j" \\"
        done 2> outputspeler.txt
        for (( i=0; i<${#muzieklijst[@]}; i=$i=1))
        do
            if [ "$muzieklijst[i]" = `cat outputspeler.txt` ]
            then
                mpg123 muziekpadlijst[$i]
                continue
            fi
        done

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Odisee Technologiecampus Ghent, Ghent, Belgium, Joris Maervoet, B-ODISEE-JLW375-1718

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

---------- Post updated at 04:58 PM ---------- Previous update was at 04:41 PM ----------

I have to add, that I'm allowed to get help if I write where I got help from.
# 2  
You seem to have a few problems.

You do not seem to fully understand how to use array variables. You cannot directly use a for loop to create a list of operands to a utility (and, with an array, there doesn't seem to be any need to try to use a for loop to create your dialog operand list).

Please try looking at the following code and guess at what the output will be. Then run the code and see if it does what you guessed it would do. For these examples, first create an array containing 4 items:
Code:
$ array=(item0 "item 1" "I am $USER" 'I am $USER')

Note that my login name is "dwc", so the expansion of $USER for you will probably be something different that what I show in my sample output below. Let us verify that array[] contain 4 elements with the expected values:
Code:
$ printf 'array contains %d elements\n' ${#array[@]}
array contains 4 elements
$ for i in ${!array[@]}
do      printf 'array[%d] is "%s"\n' $i "${array[$i]}"
done
array[0] is "item0"
array[1] is "item 1"
array[2] is "I am dwc"
array[3] is "I am $USER"
$

Is there anything above that surprised you?

Now let's try some of the array references used in your code. What would you expect the output to be from the following code:
Code:
$ i=2
$ printf '"%s"\n'  "$array[i]" array[$i] "${array[$i]}" ${array[$i]} '${array[$i]}'

Note that the first two arguments to this printf statement are logically equivalent to two of the array references in the code you showed us. Did they produce the output you were expecting?

Now run that code. Did any of these arguments produce the output you were expecting?

After running all of the above code, would you expect the output from the following two commands to be the same or be different:
Code:
$ printf '%s\n' "${array[i]}"
$ printf '%s\n' "${array[$i]}"

Now run the code. Did you get the output you were expecting?

Does any of this help with your homework assignment?

Does knowing that the output produced by:
Code:
$ printf '%s\n' "${array[@]}"

is:
Code:
item0
item 1
I am dwc
I am $USER

help you?
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Dialog menu with array
dan007255
Hi I'm currently making a schoolproject and I'm stuck with reading an array into the possible options of a menu dialog. What I mean is: I've put some values into an array, I want all these values from the array to be possible to be selected in the menu. Please help :) I'm programming in Debian...... Shell Programming and Scripting
1
Shell Programming and Scripting
Dialog --menu limitation for the entries for selection
ww889
Hi Guys, Please pardon me if this is a silly question, but I have tried to find an answer and going through the man page and failed to get one. I have created a menu driven script with dialog --menu option. Everything is working as expeted, however, it seems that if I have more than 10...... Shell Programming and Scripting
1
Shell Programming and Scripting
dialog menu script. please HELP
claudlu
hello. i want to create a useradd dialog menu. i cannot make a single menu with 4 box inputs ( user, pass, fullname, shell ) because the dialog utility is either limited or either i know to less about using the dialog utility. from what i see it only allows me to post these 4 boxes one by one,...... Shell Programming and Scripting
3
Shell Programming and Scripting
Unix / Linux Dialog Utility - how to open 2+ more dialog windows ?
jack2
Hi, example of Unix / Linux dialog utility is below. I am going to use dialog as simple GUI for testing of a modem. So I need to combine some dialog boxes into one. I need to have input box, output box, info box, dialog box, radiobox as in any standard program with graphical user...... Shell Programming and Scripting
2
Shell Programming and Scripting
Menu help with array selection
draco
Hi there all I got the following I got multiple arrays named for example STAT_AAAA STAT_AAAB STAT_AAAC STAT_AAAD Now what I want I have chosen an option in a menu to select 1 but I dont want to write for all the same thing so I made it a signle one now what I want is to get STAT_ and...... Shell Programming and Scripting
6
Shell Programming and Scripting