This is a short program I wrote to search through a directory and move files containing the keyword to a folder.
#!/bin/bash
echo 'What is the directory?'
read DIR
echo -e '\n'
echo 'What is the keyword?'
read KEY
echo -e '\n'
cd $DIR
rmdir 'relevant_files'
mkdir 'relevant_files'
for entry in 'grep -ilr $KEY $DIR'; do
echo $entry
mv $entry 'relevant_files'
done
The main problem I'm having with is the for loop.
for entry in 'grep -il $KEY $DIR'; do
echo $entry
mv $entry 'relevant_files'
done
My question is, how would I make the for loop entries equal to each file grep comes up with in the directory?
because I want to see diagnostic messages if one or more of the files being processed can't be opened for reading, or have been renamed or deleted by something else while this script is also processing files in this directory.