I have two arrays: options and args, and I want to display the contents of arrays. For that I wish to write a general function which will take the name of array and display its contents.
eg.
set -A options val1 val2 val3
set -A args var1 var2 var3
What I am doing now to display the contents:
dispArr() {
i=0
while [ "$i" -lt "${#options[*]}" ] #line1
do
echo ${options[$i]} #line2
((i=i+1))
done
}
currently I have two different functions, one for array "options" and other for array "args"
I want to substitute array names ("options" in above code) in line1 and line2 with variables, so that I can make a call like following to print the contents of any array :
dispArr options #print the contents of array "options"
dispArr args #print the contents of array "args"
I tried providing $1 in place of array names but it didn't work. I also tried different quotes but it didn't work too.
I am new to unix and shell scripting, so any advice would be appreciated. Thanks in advance.
ksh --version-- empty output, then it's ksh88