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!
cd
back aftercd "$Dir"
or use subshell) – grochmal Oct 6 '16 at 22:00cd
. I corrected readability. Onedone
was missing. – user147505 Oct 6 '16 at 22:08