learning bash scripting and i'm trying to filter results with a nested grep in a for loop:
sample filenames:
this-file_AAC.txt
this-other_file_AAAC.txt
yep-a-file_AAC.nfo
oops_another_one.reamde
and this is the script:
shopt -s globstar nullglob dotglob
for file in ./**/*.{txt,reamde,nfo}; do
printf "input: ${file}\n"
if grep -qF _AAC $file; then
printf "output: ${file}\n"
# do stuff with $file
fi
done
the idea being any file that contains _AAC will have operations applied to it; in this specific case, just print to stdout to confirm the results are correct.
problem is: nothing makes it past the if statement. so i'm missing i-don't-know-what. all that works is the printf "input... line.
what am i missing?
grepis looking inside the content of the file... are you trying to apply a command if the name of the file contains _AAC?grepworked on a filename as well... sounds like it doesn't?for file in ./**/*_AAC*.{txt,reamde,nfo}; do ...for file ! in ./**/*_AAC*....?