csh grep analog

Hi everyone, I'm trying to make a csh script analog for grep.

I need to run through the directory which is arg[1], find a word (arg[2]) in the files, and echo their names.

Here's what I got

if ($#argv != 2) then
  echo "Usage: $0 directory word"
  echo "Shows files which contains words"
  exit 0
endif
set dir = $argv[1]
if (! -d "$dir") then
  echo "$dir is not a directory" 
  exit 1
endif
foreach file ($dir/*)
if (! -d "$file") then
  set arr = (`cat $file`)
  set i = 0
  foreach i (0..$#arr) 
    if ($arr[$i] == $argv[2]) then
      echo $file
    endif
    @ i ++
  end   
endif
end

What condition do I need to use, to run through the array of words? Because, obviously, while i <= $#arr says "=: directory not found":wall:

Okay, used foreach instead, now it says "missing -."

Is this homework?

Sadly - yes, and I have to do it on csh=\

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.