grep doesn't work within shell script?

I am trying to run the following code from a script file but it complains that syntax of (both instances of) grep is wrong.

When I copy and paste it to the terminal, it is OK. Any idea what the problem might be?

set i = `grep -c #define flags.h`

while ($i>20)
@ i--
my func (`cat flags.h | grep #define |sed -n '$i{p;q;}' `)
end

Thanks,
Baris

Hello,

Are you running your shell script under a different shell? ie csh as your command line shell and sh or ksh within your shell script?

Cheers
Helen

Helen,

Thanks for the reply. No I am using csh as my command line shell and for the script...

Baris

Change your grep statement -

old: grep -c #define flags.h

to any of these -

grep -c '#define' flags.h
grep -c \#define flags.h
grep -c "#define" flags.h

Yes, that is the solution. Thanks a lot.