I could search lines that contain two specific words using the following in multiple files:for f in $(ls *.txt); do  echo >$f; more $f | grep word1 | grep word2doneNow, I want to write a shell script to accomplish this so that I don't have to retype the whole thing again and again. I also wanted to add an option of using either one word or two words in the search.  I will be passing these searched word to the shell script at the command line.  I wrote the following shell script searchwords.sh:word1=$1word2=$2for f in $(ls *.txt); doecho >$f###if word2 is empty; then execute if [-z $word2]; then        more $f | grep $word1else###if word2 is not empty        more $f | grep $word1 | grep $word2fidoneUsage:sh searchwords.sh word1 word2Although I got what I want, I am also getting an error ouput[-z: not foundI know my code is not right, but I cannot place it.
grep two searched words
shell script;grep