| | |
resetting an array
Thread Solved |
Hi,
I am looping through some files, gathering information into an array during that loop. The array grows with the loop counter and at every point might be longer or shorter (more or less members in it)
so in order to reuse the array I need to drop all values in it, and I can't seem to find an easy way to do so (to loop through the array using its length and putting NULL into every position is a bit too much)
Example:
.tree file looks like this:
# cat /tmp/imagetrees/base33111.tree
base33111
base3311
base331
base33
base3
# cat /tmp/imagetrees/base33.tree
base33
base3
I am looping through some files, gathering information into an array during that loop. The array grows with the loop counter and at every point might be longer or shorter (more or less members in it)
so in order to reuse the array I need to drop all values in it, and I can't seem to find an easy way to do so (to loop through the array using its length and putting NULL into every position is a bit too much)
Example:
Shell Scripting Syntax (Toggle Plain Text)
i=1 for tree in `ls -A /tmp/imagetrees/*.tree` do for line in `cat $tree` do array[$i]=$line let i=$i+1 done echo ${array[*]} > i=1 # need to reset array to NULL here, before reusing in the next loop done
.tree file looks like this:
# cat /tmp/imagetrees/base33111.tree
base33111
base3311
base331
base33
base3
# cat /tmp/imagetrees/base33.tree
base33
base3
Real stupidity always beats Artificial Intelligence. (Terry Pratchett)
BA BizMg, MCSE, DCSE, Linux+, Network+
BA BizMg, MCSE, DCSE, Linux+, Network+
![]() |
Similar Threads
- Resetting the clock() (C++)
- Counting numbers in an array (C++)
- help (C++)
- Resetting arrays (C)
- setTimeout prevents resetting of image (JavaScript / DHTML / AJAX)
- Why Data Structures???...QUESTIONS INSIDE (C++)
- Maxtor slave shows up in DOS but not XP (Storage)
Other Threads in the Shell Scripting Forum
- Previous Thread: too many arguments
- Next Thread: Best way to skip first line?
| Thread Tools | Search this Thread |






