.
├── a1
│ ├── q
│ ├── w
│ └── e
├── a2
│ ├── q
│ ├── e
│ └── s
I want a nested for-loop & find $ if-statement that has to work in the linux.
The expected output is the structures of sub-directory after checking if it contains a specific string in declared array.
declare -a folderlist=("a1", "a2")
declare -a checklist=("w", "s")
for folder in "${folderlist[@]}";
do
subfolders=$(ls ./$folder);
for subfolder in "${subfolders[@]}";
do
if [ $d == "w" -o $d == "s" ];
then echo ./$folder/$subfolder;
fi;
done;
done;
do
if [ $d == "w" -o $d == "s" ];
then echo ./$folder/$subfolder;
fi;
done;
./a1/w/
./a2/s/
Why not use find for the whole thing?
# Test directory
$ find .
.
./a1
./a1/e
./a1/q
./a1/w
./a2
./a2/e
./a2/q
./a2/s
# Find sub-directories called `s` and `w`
$ find . -mindepth 2 -type d -name w -or -name s
./a1/w
./a2/s
$ find . -mindepth 1 -maxdepth 1 -type d \( -name a1 -o -name a2 \) -print0 |
xargs -0 -I{} find {} -type d -name w -o -name s
./a1/w
./a2/s