Results 1 to 10 of 12
I use array in korn shell
set -A color red blue green
set -A mobile nokia se moto
m=color
k=mobile
I am able to echo the color like below
# ...
- 07-31-2007 #1Just Joined!
- Join Date
- Jul 2007
- Posts
- 6
korn shell array
I use array in korn shell
set -A color red blue green
set -A mobile nokia se moto
m=color
k=mobile
I am able to echo the color like below
# echo ${color[1]}
red
however, I am not able to echo the variable like below
# echo ${$m[1]}
ksh: ${$m[1]}: bad substitution
any idea?
- 07-31-2007 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
You have to define m & k as arrays like you did color and mobile
Code:set -A color red blue green set -A mobile nokia se moto set -A m ${color[*]} set -A k ${mobile[*]}
- 07-31-2007 #3Just Joined!
- Join Date
- Jul 2007
- Posts
- 6
Thanks for your reply
I am not going to pass the whole array to m or k.
what i want is use m or k as the name of array
color is the name of first array
set -A color red blue green
${array name[index]}
# echo ${color[1]}
red
# echo ${$m[1]}
instead of using color as array name directly...my script actually need to use $m to replace the array name....
I tried many combination but cant work also
echo "${$m[1]}"
echo ${"$m"[1]}
echo $"{"$m[1]"}"
echo ${`echo $m`[1]}....
- 07-31-2007 #4Linux User
- Join Date
- Jun 2007
- Posts
- 318
Try this:
eval echo \${${m}[1]}
- 07-31-2007 #5Just Joined!
- Join Date
- Jul 2007
- Posts
- 6
- 07-31-2007 #6Linux User
- Join Date
- Jun 2007
- Posts
- 318
You forgot the 'eval'
eval echo \${${m}[1]}
- 07-31-2007 #7
- 07-31-2007 #8Just Joined!
- Join Date
- Jul 2007
- Posts
- 6
- 07-31-2007 #9Linux User
- Join Date
- Jun 2007
- Posts
- 318
The manpage for ksh states:
eval command ...
The arguments are concatenated (with spaces between them) to
form a single string which the shell then parses and executes
in the current environment.
What you're doing is constructing the command you want to execute and using eval to execute it.
- 07-31-2007 #10Just Joined!
- Join Date
- Jul 2007
- Posts
- 6


Reply With Quote
