0

This question already has an answer here:

I have a directory with some files. I want to know if a word exists in each file and then to print the filename along with a message "word exists" if the word exists and with the message"word doesnot exist" if the word does not exist in the file. $1 is my directory that I give it as a parameter

e.g. ./myscript.sh /mnt/c/User/er/Desktop/shows

I have written this code but the terminal doesnot run the commands and does not any er*ors. How can I fix it?

#!/bin/bash
for a in $( find "$1" -type f )
do
      if grep -q 'it21754' "$a" 
      then 
         grep -l "$a";echo "word exists" 
      else 
          grep -l "$a";echo "word does not exist"
      fi 
done

marked as duplicate by Stephen Kitt, Valentin Bajrami, Kusalananda, terdon Dec 12 '18 at 11:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.