The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Interactive Array Menu gecko2424 Shell Programming and Scripting 2 07-31-2008 01:19 PM
awk selection on fields amatuer_lee_3 Shell Programming and Scripting 3 05-13-2008 02:05 AM
Opt out selection drhowarddrfine Post Here to Contact Site Administrators and Moderators 5 01-24-2008 02:20 AM
tray selection amit kul UNIX for Advanced & Expert Users 3 07-16-2007 09:31 AM
Array and Selection ZINGARO Shell Programming and Scripting 4 07-15-2007 09:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2008
draco draco is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 38
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!
  #2 (permalink)  
Old 10-10-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,378


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

  #3 (permalink)  
Old 10-13-2008
draco draco is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 38
Oke and how do I use it like that than?
  #4 (permalink)  
Old 10-13-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,378

What do you want to do with it?

To store it in a variable:


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

  #5 (permalink)  
Old 10-14-2008
draco draco is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 38
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
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 (permalink)  
Old 10-14-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,378

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 (permalink)  
Old 10-15-2008
draco draco is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 38
is it somehow posible to use awk multidimensional arrays in korn?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0