Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have written a for loop to iterate through a file list in an array generated by a find command... I can only get it to make one pass but when I print the array it contains the two files that the find command was able to locate.
#!/bin/ksh
# Get current Month and Year:
RUN_DATE=$(date '+%m%y')# Find all files in directory that are for current month and put list in array
cd /path to files/here
set -A INPUT_FILE_LIST - `find *FILE$RUN_DATE.txt`
export INPUT_FILE_LIST
echo Show what Array is holding: "${INPUT_FILE_LIST[*]}"
#Loop Through List of Files to be processed
for FILE in $INPUT_FILE_LIST ; do
APP_NAME=`echo $FILE | cut -c1-3`
echo Now Processing $FILE from $APP_NAME Application
done
# script ends

You display "${INPUT_FILE_LIST[*]}" but you are only looping through $INPUT_FILE_LIST.
"for f in list; do..."
doesn't need an array, just one or more words separated by ${IFS} (default is spaces and tabs). Therefore you need something like:for f in *$RUN_DATE.txt; do
...
donebtw, `` is the old Bourne shell expression evaluation syntax generously supported by Korn shell for backward compatibility. $() is Korn shell and IMHO way better.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |