0

I have array1, array2 and a function.

I am trying in a for j=0 to ARRAY_SIZE loop to get the data from array2[j], pass it to a function and the returning output store it in array1[j].

Below is the part of the code that I am working on:

exec 3>&1
${ppart_block_fstype[$i]}=_ppart_block_fstype < <(
    for i in $(eval echo {0..$ARRAY_END})
    do
        if [[ ppart_block_alloc[$i] -eq "ALLOC" ]]
        then
            printf "%s\n" "${ppart_block_num[$i]}" >&3
        fi
    done)
exec 3>&-

_ppart_block_fstype is the function that I have previously defined and will return an output that I will store in array ppart_block_fstype. The problem of above function is that is using some "heavy tools", hence is not really possible to invoke it at every loop cycle.

This! was a good starting point, but I am stuck on how to make $i visible out of the subshell, and I am also not sure if I am invoking < <( )* in the correct way.

Community
  • 1
  • 1
  • Are you trying to store a corresponding entry in `ppart_block_fstype` for each entry in `part_block_num`? One problem is that your for loop may produce fewer than `ARRAY_END` lines of text. Another is its not clear what `_ppart_block_fstype` is producing for output; presumably, it write multiple lines of output, one per line of input, but you'd have to assign each line to an element of `ppart_block_fstype` separately. – chepner Oct 04 '13 at 19:05
  • Btw, you'd be better off using `seq 0 $ARRAY_END`, or even `for (i = 0; i < $ARRAY_END; ++i)`, then doing `$(eval echo {0..$ARRAY_END})`. – Rubens Oct 04 '13 at 19:41
  • I believe (maybe mistakenly) that `ksh` is a little more lenient with its scoping of variables, but as you say 'how to make `$i` visible out of the subshell ...' I don't really think that is possible. Just to be clear, you want the value for $i from inside the `for` loop from the `process substition` to be used as the value of `$i` in the array index? – shellter Oct 04 '13 at 19:47
  • @chepner I am aware that the loop may produce fewer than `ARRAY_END` entries, that is OK, my `ppart_block_fstype` is pre-initialized. `_ppart_block_fstype` accepts one argument as input and produce one line of output through `printf`, this output has to be stored in `ppart_block_fstype` – mateusz.burger Oct 04 '13 at 20:27
  • @shellter _you want the value for $i from inside the for loop from the process substition to be used as the value of $i in the array index?_ Correct – mateusz.burger Oct 04 '13 at 20:34

0 Answers0