I have a list of folders. In every of those folders there may or may not be one or two files of a particular extension (specifically ".fastq" extension). What I want to do is write a script that enters these folders, checks if fastq file exists or not. The script I've written is below :
#!/bin/bash
echo Beginning operation
echo
for folder in $(ls -d */);
do
cd ${folder%%/};
myfolder=${folder::-1}
echo
echo Entered $myfolder
fastq_test=(´find ./ -maxdepth 1 -name "*.fastq"´)
if [ ${#fastq_test[@]} -gt 0 ];
then
echo There are FASTQ files, will not do the operation
else
echo There are no FASTQ files, proceeding with operation
#operation here
fi
cd ..
echo Exited $myfolder
echo
done
echo Ended Operation
My problem is that this script doesn't work - it finds FASTQ files in folders that do not have them. Is there any better way?