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 -."