Variable substitution in ksh array

Discussion in 'Shell Script' started by abrmhk, Aug 28, 2010.

  1. abrmhk

    abrmhk New Member

    Aug 28, 2010
    Likes Received:
    Trophy Points:
    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 
       set -A SCRIPT_${SCRIPT_LINES} ${VAR1} ${VAR2} ${VAR3} ${VAR4} ${VAR5}
    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  
    (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                                         
    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.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice