I didin't add this to the FAQ thread 'cause I didn't think it qualified a "most commonly asked" question.
I understand how to call elements of an array in a bash script and how to manually populate the array, but I want to know how to automate the task of populating the array.
For example, suppose I have 10 zip files in a directory. I want my script to start by the creating an array that places the name of each of those files in an array. The array would then feed a while loop.
The size of the array created and populated would change from one execution to another, depending on the number of zip files present in the directory.
In practice, the sequence of events would look like:
- run script
- script places zipfile0.zip in array[0]
- script places zipfile1.zip in array[1]
.
.
.
- script places zipfile(n-1).zip in array[n-1]
- script places zipfile(n).zip in array[n]
- script continues on to next phase
Any ideas? If I need to clarify, just let me know.
Thanks!
N
I understand how to call elements of an array in a bash script and how to manually populate the array, but I want to know how to automate the task of populating the array.
For example, suppose I have 10 zip files in a directory. I want my script to start by the creating an array that places the name of each of those files in an array. The array would then feed a while loop.
The size of the array created and populated would change from one execution to another, depending on the number of zip files present in the directory.
In practice, the sequence of events would look like:
- run script
- script places zipfile0.zip in array[0]
- script places zipfile1.zip in array[1]
.
.
.
- script places zipfile(n-1).zip in array[n-1]
- script places zipfile(n).zip in array[n]
- script continues on to next phase
Any ideas? If I need to clarify, just let me know.
Thanks!
N
