[ale] Bash question: | in find

Joe jknapka at earthlink.net
Sat Jan 25 02:18:46 EST 2003


Geoffrey <esoteric at 3times25.net> writes:

> Joe wrote:
> > Geoffrey <esoteric at 3times25.net> writes:
> >
> >>I'm trying to figure out what you're trying to do there. I think
> >>you're trying to locate the tarball that contains the Xawd library??
> > Yes, in this particular instance. But more generally, I want
> > to know how to execute a pipeline (as opposed to a single
> > command) in an "-exec" clause in a "find" command.
> >
> >>Why not let tar do the 'grep' for you:
> > Well, because I didn't know tar would do that :-)
> >
> >>for fn in $(find /cdrom/slackware -name '*.tgz' -print); do
> >>	echo -n $fn " "
> >>	tar tvzf $fn '*libXaw3d*' 2>/dev/null
> >>done |grep Xaw3d
> > Nice. Thanks.
> >
> >>'echo -n' will print the file name without a newline, so the output of
> >>tar will be appended to the filename, and the 'grep' on the output of
> >>the for loop will print only those lines that contain the Xaw3d, hence
> >>all the files that did not contain the file you're looking for will be
> >>filtered out.
> > One slight problem: it needs an "echo" *after* the "tar" command,
> > otherwise *everything* comes out on one line.
> 
> That's wierd.  Must be a bash bug, as it doesn't do that under
> ksh.

Why weird? We're telling echo not to put any newlines anywhere, so
unless and until "tar" spits out a result that doesn't go to stderr,
we get a huge list of files, all on one line.  The tar command isn't
going to emit a newline to stdout when it doesn't find the file we're
asking for, right?  So the "grep" spits out that line, and the last
file listed is the one containing the string.  Perhaps ksh emits a
newline after the tar command for some reason, and bash doesn't?

BTW, I used this, and discovered that in Slackware, the libXaw3d.so
lives in the "l" distro directory, not (as I was expecting) "x" or
"xap".

Cheers,

-- Joe
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list