I want to look into a folder to see if there are any folders within it. If there are, I need to check inside each folder to see if it contains a .pdf file
So
If /myserver/myfolder/
contains a folder AND that folder conatins a .pdf file
do X
Else
do Z
I may have multiple folders and multiple .pdf files under myfolder. I don't know ahead of time what the folder should be called to do a test. I don't care about the folder name. I don't know what the pdf should be named ahead of time to do a test either. I just care that something ending in .pdf is in the folder under myfolder.
So for each subdirectory, if the subdirectory contains a PDF file, do X, else do Y. What if there are multiple PDF files in a directory? The following will loop over them.
set -o nullglob
for f in /myserver/myfolder/*/; do
pdf=false
for p in "$f"/*.pdf; do
X
pdf=true
done
if ! $pdf; then
Z
fi
done
It is ok if a subdirectory contains multiple pdf files. It only needs to have at least one. If I have NO subdirectory OR any subdirectory withOUT a pdf, that should arrive at the same Z error.
That's a script, but it doesn't really conform to your requirements. Specifically, it ignores the case when there is no subdirectory.
The following is a bit contorted but should perhaps work.
#!/bin/sh
set -o nullglob
pdf=false
for f in /myserver/myfolder/*; do
test -d "$f" || continue
for p in "$f"/*.pdf; do
pdf=true
X
break
done
$pdf || break
done
$pdf || Z