you need array not awk, please refer to your shell array assignment
-bash-3.2$ x=(first second third fourth)
-bash-3.2$ echo ${x[0]}
first
-bash-3.2$ echo ${x[1]}
second
-bash-3.2$ echo ${x[2]}
third
-bash-3.2$ echo ${x[3]}
fourth
-bash-3.2$
Thanks for your replies. I tried set and array solutions but it didn't work.
I'm using ksh in AIX 5.3
Here is my input string
-parm a=b -parm c=d -parm e=f -parm g=h \
Note: At the end of each line in my input file there is a Back slash charater.
My input string can be of variable length. For example it can be
-parm a=b -parm c=d \
or
-parm a=b -parm c=d -parm e=f \
My requirement is to check for values for each -parm and do a particular action.
For example if my input string is
-parm a=b -parm c=d -parm e=f -parm g=h \
If the last -parm value is g=h then I need to set a variable X to 1.
If the 2nd -parm value is a=b then I need to set a variable Y to 1.
That is I need to read the value one at a time from my input string and perform a particular action.
I thought it would be possible in awk and hence my original question.
Your different approachs to this problem or solutions to this problem is highly appreciated.
$ set -A x a b c
$ echo ${x[1]}
b
$ echo ${x[0]}
a
But when i try my input text i get errors as below
Try 1
$ set -A x -parm a=b -parm c=d -parm e=f -parm g=h \
>
ksh: -parm: 0403-010 A specified flag is not valid for this command.
Try 2
$ set -A x -parm a=b -parm c=d -parm e=f -parm g=h \\
ksh: -parm: 0403-010 A specified flag is not valid for this command.
Try 3
$ set -A x '-parm a=b -parm c=d -parm e=f -parm g=h \'
ksh: -parm a=b -parm c=d -parm e=f -parm g=h \: 0403-010 A specified flag is not valid for this command.
The reason why I want to do this is like I mentioned before the number of arguements may vary in my input and one of my requirement is to get the last - 1 parameter.
For example
This works fine when $4 or $1 is an arguement to echo.
But I need the 6th parameter of set which is e=f and this position varies based on my input line. Sometimes it might be 7th position as shown in above example and sometimes it may be 3rd.
I think there are two answers here. First, you seem to be asking how to access a variable-variable name. In other words, I want to define a variable name with a variable since I don't know something about the code before it runs. Try this:
set a b c d
field=3
eval echo '$'$field
Second, you seem to want this so you can grab the last field from the original input.