arrays creating new arrays in dtksh

arrays creating new arrays in dtksh

Post by Patrick O'Lea » Wed, 25 Feb 1998 04:00:00



I have created an array in dtksh for doing the following:

  catArray[0]=/home/bmis/Servers
  catArray[1]=/home/bmis/Desktops
  catArray[2]=/home/bmis/Storage
  catArray[3]=/home/bmis/Networking


  do
    cd ${catArray[$i]}
    for dirs in *; do
      if [[ -d "$dirs" ]]; then
          dirArray="$dirArray ${catArray[$i]}/$dirs"
      fi
    done
  done


Using this array, I would like to do:


  do
    cd ${catDirArray[$i]}
    for dirs in *; do
      cd $dirs/$QUERY_STRING
      for files in *; do
          if [[ -e "$files" ]]; then
-------->   "${catDirArray[$i]##*/}Array"="${catDirArray[$i]##*/}Array $files"
          fi
      done
      cd ${catDirArray[$i]}
     done
  done

----> Points to the problem I'm encountering. I would like to
create a new array depending on where I'm at within my for loop.
So, I would like to have X # of new arrays created dependent on my
conditional "if [[ .. ]]"

Any idea how to accomplish this? I've tried for 2 days and can't
resolve it.

Thanks in advance,

Patrick

 
 
 

arrays creating new arrays in dtksh

Post by brian hil » Sat, 07 Mar 1998 04:00:00


: I have created an array in dtksh for doing the following:

:   catArray[0]=/home/bmis/Servers
:   catArray[1]=/home/bmis/Desktops
:   catArray[2]=/home/bmis/Storage
:   catArray[3]=/home/bmis/Networking


:   do
:     cd ${catArray[$i]}
:     for dirs in *; do
:       if [[ -d "$dirs" ]]; then
:         dirArray="$dirArray ${catArray[$i]}/$dirs"
:       fi
:     done
:   done


: Using this array, I would like to do:


:   do
:     cd ${catDirArray[$i]}
:     for dirs in *; do
:       cd $dirs/$QUERY_STRING
:       for files in *; do
:         if [[ -e "$files" ]]; then
: -------->   "${catDirArray[$i]##*/}Array"="${catDirArray[$i]##*/}Array $files"
:         fi
:       done
:       cd ${catDirArray[$i]}
:      done
:   done

: ----> Points to the problem I'm encountering. I would like to
: create a new array depending on where I'm at within my for loop.
: So, I would like to have X # of new arrays created dependent on my
: conditional "if [[ .. ]]"

: Any idea how to accomplish this? I've tried for 2 days and can't
: resolve it.

: Thanks in advance,

: Patrick
I must admit that I have read the specification of your problem
several times and still am not confident I completely understand
the nature of your request.

If your goal is to dynamically "invent" a variable name, one must
insert an "eval" because variable substitution occurs just once
and this hides the "indirection". Or one may use "typeset -n" to
create a "nameref" variable which could be an argument to be passed
to a function to do the "real" work.

Try (untested, my ISP doesn't have ksh93):

eval "${catDirArray[$i]##*/}Array=${catDirArray[$i]##*/}Array \$files"

Does this work for you?

-Brian

 
 
 

1. dtksh: namerefs with indexed arrays don't seem to work.

I'm using dtksh with AIX 4.1.5.

It appears that namerefs don't work with indexed arrays. That is, the
namerefs expand to the 0th element of the array (the name of the array).

Is there a way around this? The following demonstrates my point:

#!/usr/dt/bin/dtksh
nameref B=DATA[1]
B=999999
print "${!B}"
print "0 ${DATA[0]}"
print "1 ${DATA[1]}"

C[0]=xxxxx
C[1]=888888
nameref D=C[1]
print "${!D}"
print "${D}"
print "0 ${C[0]}"
print "1 ${C[1]}"

The following output is produced:

DATA
0 999999
1
C
xxxxx
0 xxxxx
1 888888

--
Jeff Dragovich
Telephone: (206) 237-1561

2. Slackware ver 2.00 Installation

3. Finding array indexes from array values

4. Default terminal type on a dialup serial port

5. scraid array how long to build arrays

6. SCO Tarantella & Windows NT 4.0 Terminal Edition

7. help to array notseeing LUNs on 2nd and 3rd disk array

8. BoboMips Actually Relative?

9. Anyone had luck with the compaq smart 2dh array controller running a compaq array box 3161?

10. SunSolstice 4.0/Array 100: How to boot from an Array disk?

11. malloc, array's, pointer array's AGHHHH!!!

12. Help required D1000 Array vs A1000 Array

13. (patch for Bash) New array builtins, New brace expansion