I need help parsing the output of
find into an array. I need to search 3 directories and find all files older than 31 days old. This is what I have so far.
When I
echo the
FIND_DIR variables, it prints out..
/dir1/file1 /dir1/file2 separated by what I'm assuming is either white space or a tab.
The issue I'm having is when I try to put the output of the find into an array, array index 0 has both /dir1/file1 and /dir1/file2
I need array index 0 to be file 1 and array index 1 to be file 2.
The above code will output /dir1/file1 for both array index 0 and array[@], it prints nothing when asked to print array index 1.
Thank you in advance.
Code:
TIME=" -maxdepth 1 -mtime +31"
DIR1="/dir1/"
DIR2="/dir2/"
DIR3="/dir3/"
FIND_DIR1=$(find ${DIR1}${TIME})
FIND_DIR3=$(find ${DIR2}${TIME})
FIND_DIR3=$(find ${DIR3}${TIME})
IFS=' ' read -a array <<< "$FIND_DIR1"
for element in "${array[@]}"
do
echo "$element"
done
/dir1/file1 /dir1/file2 separated by what I'm assuming is either white space or a tab.
The issue I'm having is when I try to put the output of the find into an array, array index 0 has both /dir1/file1 and /dir1/file2
I need array index 0 to be file 1 and array index 1 to be file 2.
The above code will output /dir1/file1 for both array index 0 and array[@], it prints nothing when asked to print array index 1.
Thank you in advance.