0

Hi
I am reading x lines from a text file into an array per line:

integer SCRIPT_LINES=0 while read VAR1 VAR2 VAR3 VAR4 VAR5 do .... SCRIPT_LINES=$SCRIPT_LINES+1 set -A SCRIPT_${SCRIPT_LINES} ${VAR1} ${VAR2} ${VAR3} ${VAR4} ${VAR5} ... done [/CODE=ksh]

This creates a number (SCRIPT_LINES) of arrays: SCRIPT_1, SCRIPT_2, SCRIPT_3, ....

Now I want to use the contents of these arrays one by one. Each array is read using a for loop:

[CODE=ksh] for var in `echo ${SCRIPT_1[*]}`; do echo $var nohup sqlplus -l / @$AFVM/$AA/scripts/$var.sql > $log_dir/$var"_"$dat.log 2>&1 & done [/CODE=ksh]

(starting up to 5 sql-scripts in background)

I want to make an outer loop to run thru all the arrays, substituting the _1, _2, _3 etc with $X, where X is sequence from 1 to SCRIPT_LINES. The obvious thing to do, was to change for statement to: [CODE=ksh] for var in `echo ${SCRIPT_$X[*]}`; do [/CODE=ksh]

but this is not allowed in ksh: invalid substitution. I have tried echoing etc, but I haven't a solution.

Is there a way to loop thru arrays the way I want - as suggested above or any other way ?

I am running AIX 5.3 with the old ksh (88), but have access to ksh93 and bash as well.

Regards, Mogens[CODE=ksh]
integer SCRIPT_LINES=0
while read VAR1 VAR2 VAR3 VAR4 VAR5
do
....
SCRIPT_LINES=$SCRIPT_LINES+1
set -A SCRIPT_${SCRIPT_LINES} ${VAR1} ${VAR2} ${VAR3} ${VAR4} ${VAR5}
...
done
[/CODE=ksh]

This creates a number (SCRIPT_LINES) of arrays: SCRIPT_1, SCRIPT_2, SCRIPT_3, ....

Now I want to use the contents of these arrays one by one.
Each array is read using a for loop:

for var in `echo ${SCRIPT_1[*]}`; do echo $var nohup sqlplus -l / @$AFVM/$AA/scripts/$var.sql > $log_dir/$var"_"$dat.log 2>&1 & done [/CODE=ksh]

(starting up to 5 sql-scripts in background)

I want to make an outer loop to run thru all the arrays, substituting the _1, _2, _3 etc with $X, where X is sequence from 1 to SCRIPT_LINES. The obvious thing to do, was to change for statement to: [CODE=ksh] for var in `echo ${SCRIPT_$X[*]}`; do [/CODE=ksh]

but this is not allowed in ksh: invalid substitution. I have tried echoing etc, but I haven't a solution.

Is there a way to loop thru arrays the way I want - as suggested above or any other way ?

I am running AIX 5.3 with the old ksh (88), but have access to ksh93 and bash as well.

Regards, Mogens[CODE=ksh]
for var in `echo ${SCRIPT_1[*]}`; do
echo $var
nohup sqlplus -l / @$AFVM/$AA/scripts/$var.sql > $log_dir/$var"_"$dat.log 2>&1 & done
[/CODE=ksh]

(starting up to 5 sql-scripts in background)

I want to make an outer loop to run thru all the arrays, substituting the _1, _2, _3 etc with $X, where X is sequence from 1 to SCRIPT_LINES.
The obvious thing to do, was to change for statement to:

for var in `echo ${SCRIPT_$X[*]}`; do [/CODE=ksh]

but this is not allowed in ksh: invalid substitution. I have tried echoing etc, but I haven't a solution.

Is there a way to loop thru arrays the way I want - as suggested above or any other way ?

I am running AIX 5.3 with the old ksh (88), but have access to ksh93 and bash as well.

Regards, Mogens[CODE=ksh]
for var in `echo ${SCRIPT_$X[*]}`; do
[/CODE=ksh]

but this is not allowed in ksh: invalid substitution.
I have tried echoing etc, but I haven't a solution.

Is there a way to loop thru arrays the way I want - as suggested above or any other way ?

I am running AIX 5.3 with the old ksh (88), but have access to ksh93 and bash as well.

Regards,
Mogens

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by scoude
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.