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!
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
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
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:
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:
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.