Menu help with array selection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Menu help with array selection
# 1  
Old 10-10-2008
Menu help with array selection

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 than the selected one
How is this done?
so example
${STAT_AAAA} AAAA should be able to change by selection..
I got AAAA and AAAB also in a variable.
${STAT_ *Variablename*[2]}
how can this be done?
Many thanx in advance! Smilie
# 2  
Old 10-10-2008

Code:
eval "printf '%s\n' \"\${STAT_$VAR[2]}\""

This User Gave Thanks to cfajohnson For This Post:
# 3  
Old 10-13-2008
Oke and how do I use it like that than?
# 4  
Old 10-13-2008

What do you want to do with it?

To store it in a variable:

Code:
eval "value=\${STAT_$VAR[2]}"

# 5  
Old 10-14-2008
Can I use an array in an array??
So I can use someting multiple times instad of making for every array the same?

As in
${array${array[*][1]}}

I got this now but maybe I can make someting much easyer for this wich also cost less lines Smilie
So if I would put the 4 letter words such as XFWT in an array aswell and than call it up inside an array...
If I make anny sense that is :P

Code:
if [ ${STAT_XFWT[2]} = "running" ]
then
        STAT_XFWT[2]='\033[1;32mRunning\033[m'
else
        STAT_XFWT[2]='\033[1;31mStopped\033[m'
fi

if [ ${STAT_XMCT[1]} = "up" ]
then
        STAT_XMCT[1]='\033[1;32mUP\033[m'
else
        STAT_XMCT[1]='\033[1;31mDown\033[m'
fi

if [ ${STAT_XMCT[2]} = "running" ]
then
        STAT_XMCT[2]='\033[1;32mRunning\033[m'
else
        STAT_XMCT[2]='\033[1;31mStopped\033[m'
fi

if [ ${STAT_XMCA[1]} = "up" ]
then
        STAT_XMCA[1]='\033[1;32mUP\033[m'
else
        STAT_XMCA[1]='\033[1;31mDown\033[m'
fi

if [ ${STAT_XMCA[2]} = "running" ]
then
        STAT_XMCA[2]='\033[1;32mRunning\033[m'
else
        STAT_XMCA[2]='\033[1;31mStopped\033[m'
fi

if [ ${STAT_ZAMI[1]} = "up" ]
then
        STAT_ZAMI[1]='\033[1;32mUP\033[m'
else
        STAT_ZAMI[1]='\033[1;31mDown\033[m'
fi

if [ ${STAT_ZAMI[2]} = "running" ]
then
        STAT_ZAMI[2]='\033[1;32mRunning\033[m'
else
        STAT_ZAMI[2]='\033[1;31mStopped\033[m'
fi

# 6  
Old 10-14-2008

No shell that I know of has multidimensional arrays (but awk does).

You can use the contents of an array as an element in another array, but it will no longer be an array. You may be able to reconstruct an array from it.

For example:

Code:
a1=( 1 2 3 4 5 6 7 8 )
a2=( a b c d e f g h )
b=( "${a1[*]}" "${a2[*]}" )
printf "%s\n" "${b[@]}"

To reconstruct the arrays:

Code:
a1=( ${b[0]} )
a2=( ${b[1]} )

If the array elements contain spaces, you will have to use a different delimiter when storing an array in the enclosing array.
# 7  
Old 10-15-2008
is it somehow posible to use awk multidimensional arrays in korn?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selection from array

Hi, I need some help taking a selection from a command and adding part of the output to an array. I'd like to read the items into the array, have the user chose an option from the array and put the item from column 1 into a variable. The command is: awless -l list routetables --columns... (7 Replies)
Discussion started by: bignellrp
7 Replies

2. Homework & Coursework Questions

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... (1 Reply)
Discussion started by: dan007255
1 Replies

3. Shell Programming and Scripting

Dialog menu with array

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... (1 Reply)
Discussion started by: dan007255
1 Replies

4. Shell Programming and Scripting

Dialog --menu limitation for the entries for selection

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... (1 Reply)
Discussion started by: ww889
1 Replies

5. UNIX for Dummies Questions & Answers

Dynamic menu selection? Help..

Hi guys, i would like to create a program that allow user to show the information of certain thing such as network card. I would like the menu to be dynamic, for example: my computer system have 2 network card inserted at the moment, therefore the menu will have 2 choice for the user. eth0... (12 Replies)
Discussion started by: malfolozy
12 Replies

6. Shell Programming and Scripting

A selection menu in a shell script

I'm writing a shell script and have a problem with selection when I issue the command, is there a way to automatically choose a selection number one after a selection menue appear Command 1-choice 2- choice 3-choice Thanks Sara (3 Replies)
Discussion started by: Sara_84
3 Replies

7. Shell Programming and Scripting

reprint the select menu after a selection

Hi, I am using a select in ksh for a script #!/bin/ksh FIRSTLIST='one two three four quit' PS3='Please select a number: ' select i in $FIRSTLIST ; do case $i in one) print 'this is one' ;; two) print 'this is 2' ;; three) print 'this is 3' ;; four) print... (7 Replies)
Discussion started by: omerzzz
7 Replies

8. UNIX for Dummies Questions & Answers

Input A Menu Selection In A Variable

hey all, me again....having a problem with my code, where I essentially am trying to show a menu, have the user select an option (from 1 to 5), then display which selection they picked... #!/bin/bash # A LIST OF THE ERROR MESSAGES AND THE PROPER SYNTAX: error_0="Correct amount of... (1 Reply)
Discussion started by: SoVi3t
1 Replies

9. Linux

Opt out of selection menu?

When I logon to my server with PuTTY I am forced into a selection menu with few options. How to I opt out of this menu to get to the home directory to view all of the files on the server? Thanks for the help. :o (1 Reply)
Discussion started by: ksirimarco
1 Replies

10. Shell Programming and Scripting

Array and Selection

I have a question: Y X Tabel a is a array multidimensional --> a(1024,20) I load in to array a Text from 6000 row where: in a(1,1) is present the row 1 of original text, in a(1024,1) is present then row 1024 of original test and in... (4 Replies)
Discussion started by: ZINGARO
4 Replies
Login or Register to Ask a Question