I have an array that contains a list of filenames (without extension) ex:
filearray=("fileA" "fileB" "fileC")
These files are split amongst multiple directories. As I loop through the directories, I would like to perform an operation on the files from the array that are present in each directory. How can I use find or grep with an array?
Can I do something like this?:
Dirarray= ("dirA" "dirB")
for Dir in "${Dirarray[@]}"; do
cd "$Dir";
for file in "${filearray[@]}"; do
if find . -regextype posix-extended -regex "$file"; then;
do X;
fi;
done
done
Thanks!
cdback aftercd "$Dir"or use subshell)cd. I corrected readability. Onedonewas missing.