0

I have a bash script that inputs lines into a html file, this is done in a loop through an array. Later in the script i loop through a different array that may contain the same values as in the previous array so i want to check if a string from my array appears in my html file already do this, else do something else.

currently i have this:

if grep -rnw MY_HTML_FILE.html -e string_from_array ; then
echo "string found">>MY_HTML_FILE.html
else
echo "string not found">>MY_HTML_FILE.html
fi

this only ever seems to go with string not found which means when the script has finished and i check the file i have duplicate enteries.

  • Could you elaborate more? In the title of the question you talk about "string 123", as if it's only one string, but later it seems like you look for a string inside an array. – guillermo chamorro Sep 24 at 11:33
  • Essentially with the if statement i am looking for the string that is from the array in my html file. if the string has been placed in the html file (previously in the same script) then echo its already there, if not then add the string. – a.smith Sep 24 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.