[H-GEN] bash command-line question [was: Re: ...self executing tar.gz's?]

Greg Black gjb at gbch.net
Wed Jun 12 00:43:32 EDT 2002


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

Tony Nugent wrote:

| I have a (bash v2) shell problem that I've been trying to solve for
| a while now, and I'm wondering if anyone has a some suggestions...
| 
| An example of what I'm trying to do:
| 
|  $ find . -type f -name \*.txt -exec command1 {} ; command2 {} | filter_prog \;

Your syntax is a bit broken.  The usual approach for the
multiple command part is this:

    find . -type f -name \*.txt -exec cmd1 {} \; -exec cmd2 {} \;

If you want all the output to be piped into your filter, then
just wrap the entire thing inside a pair of parentheses and pipe
it to the filter:

    ( find blah -exec cmd1 {} \; -exec cmd2 {} \; ) | filter

|   Oh, I'm aware of xargs...
|   $ find -type d | xargs /bin/ls -ld
|   ... but that isn't robust for what I have in mind.  It has the
|   potential to feed a huge list of files into the list of args to
|   the command that xargs runs, while "find -exec" executes for each
|   result right away.

Unless your implementation of xargs is peculiarly broken, you
can limit the number of args it uses with a command line option,
as discussed in the fine manual.

Greg

-- 
#include<stdio.h> /* compile: cc -o sig sig.c */
int main(c,v)char *v;{return!c?putchar(*v-1)&&main
(0,v+1):main(0,"Hsfh!Cmbdl!=hkcAhcdi/ofu?\v\1");}

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list