This is an assignment question, so I'm not directly looking for an answer or the script. So in one of my questions, I'm asked that I should delete the files containing any of the passed command line arguments. Here is the script snippet for that
#!/bin/sh
#some more stuff here
for args in "$@"; do
if [ $# != 0 ]; then
grep -l $args * | while read theFile;
do
if [ -f "$theFile" ] ; then
rm "$theFile"
echo "$theFile is deleted with $args match"
else
echo "$theFile not deleted"
exit 2
fi
done #end of while loop
else
echo "No match found with $args"
exit 1
fi
done
echo "DONE"
exit 0
Now, I'd like to know how I would write the script so that it would delete the files that have ALL the arguments? I understand that I need to check if each file has the arguments passed with either a for loop, but I'm not sure how I'd be writing it. Any inputs will be appreciated.
I'm using cloud9 to practice, if that info is needed.