bash script -->> arrays, Indirect Variable References--->> help :)

Discussion in 'Programming/Scripts' started by niekshas, Jun 25, 2008.

  1. niekshas

    niekshas New Member

    #well ihawe something like this

    Array=(first second)

    firstoption=(one two)

    secondoption=(11 22)

    #now i'm reading like this

    For segment in "${Array[@]}"; do
    x=$segment"option" #i'm geing something like firstoption
    eval t=\${$x[@]} #I hope that t will be array
    For opt in "${t[@]}"
    echo opt
    done
    done

    ###############

    well i hope read like all options... but cant... couse t hawe only one value "one two" or "11 22 "
    i cnow thats LAME so i'm asking... how i can improve this script ???
     
  2. burschik

    burschik New Member

    Do you mean

    HTML:
    Array=(first second)
    
    firstoption=(one two)
    
    secondoption=(11 22)
    
    #now i'm reading like this
    
    for segment in "${Array[@]}"; do
        x=$segment"option" 
        eval t=\${$x[@]} 
        for opt in ${t}; do
            echo $opt
        done
    done
    
     
  3. burschik

    burschik New Member

    Come to think of it, you may mean this

    HTML:
    Array=(first second)
    
    firstoption=(one two)
    
    secondoption=(11 22)
    
    for segment in ${Array[@]}; do
        x=${segment}option
        eval t=(\${$x[@]})
        for opt in ${t[@]}; do
            echo $opt
        done
    done
    
     

Share This Page