Variable substitution in ksh array

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

  1. abrmhk

    abrmhk New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi
    I am reading x lines from a text file into an array per line:

    Code:
    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
     

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