Have you considered the use of 'find' , e.g.:
 find . -type f -name 'your*here' -exec grep 'string options pattern ...' 
/dev/null {} \;

 a) /dev/null is there to make grep list the filename (because your term is 
found in {}, not in /dev/null
 b) -type f  excluded directories, symlinks, sockets, ...
    (grep on directories may 'report' binary stuff which can confuse your 
terminal or other 'things' downstream)
 c) if your serach terms are simple text 'fgrep' may be better, not just 
because it's faster -- it saves you a lot of \escaping.
 d) find let's you define you much other handy stuff, ctime, atime, inode,...

I didn't look too closely at your script, but it seemed like you'r not testing file type.

Sorry for the quick&sloppy response.

Happy New Year to all........................Horst


Date: Sun, 31 Dec 2006 13:33:03 -0800
From: Martin Kelly <[EMAIL PROTECTED]>
Reply-To: Eugene Unix and Gnu/Linux User Group <[email protected]>
To: Eugene GNU/Linux Users Group <[email protected]>
Subject: [Eug-lug] Strange shell behavior

I have just written a shell script that greps a directory for a certain pattern and reports each file that contains the pattern along with the filename before it (this is why I wrote it... if I just do a "ls | cat | grep pattern" or something like that it will report the text that matches but not the filename).

I am getting strange behavior in that it works, but sometimes it randomly reports the contents of my / directory. This does not always happen, only sometimes.

Here's an example:
[EMAIL PROTECTED]:~$ misc/dirgrep code/c/kr/1/ MAXLINE

1-16.c:
--------------------------------------------------------------------------------
#define MAXLINE 1000 /backups /bin /boot /dev /etc /home /initrd /initrd.img
 ...etc...

_______________________________________________
EUGLUG mailing list
[email protected]
http://www.euglug.org/mailman/listinfo/euglug

Reply via email to