Using pipes in a find command

How are pipes used inside a find -exec clause?

I want to traverse a directory tree and find all of the shell scripts, and then based on that I need to perfrom further processing. So I have something like

find . -name \*  -exec "file {} \| grep 'script' > /dev/null" \; -ls

with -ls as a simple version of the further processing!
This doesn't work, so any suggestions appreciated.

do you want to grep within files that came out from the find?
or
grep in the file names itself?

if you want all the files then better ignore the -name switch.

grep within files for the word 'script':

find . -type f -exec grep 'script' {} 2>/dev/null \;

grep within filenames:

find . -type f | grep 'script' 2>/dev/null

What OS are you using?
I would use something like this:

find <path> -type f | xargs file | fgrep script ...

Or maybe something like:

file * |grep 'script'|cut -d: -f1| ls -l

You can write something like this too,
but it will be extremely inefficient (but, in some cases, more flexible):

find <path> -type f -exec bash -c '
  f=$1 t="$(file -- "$f")"
  case $t in
    ( *script* );;
    ( * ) exit 1 ;;
  esac
  ' - {} \; -ls 

Of course, if recursion is not needed, you should use Franklin52's solution.

Thanks for the input guys, but what I want to do is:-

  1. Traverse a complete directory tree - not just a single directory
  2. I don't want to look for "script" in either the filename or the content of the file. I want to look for it in the output of the 'file' command being run on each file found in turn.
  3. I'm natively using Korn shell on Solaris 10, but could drop into bash/csh/sh if I have to!

Yes, I think I could use xargs in this case, but to an extent, I'm more interested in finding out the correct way (assuming there is one!) to use a pipe within a find -exec clause, 'cos then I can use it for all sorts of things in the future!

Jerry

Something to start with:

file `find . -type f`