[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: find question (and xargs)

On Wed, 15 May 1996, Craig Sanders wrote:

> On 14 May 1996, Kai Henningsen wrote:
> > It's find that does the replacing. None of the {}s are in the find
> > arguments, however. (And rm is not even in the xargs arguments!)
> >
> > Personally, I'd probably make a script for the split-and-remove, but
> > it should also work with a shell function.
> A function probably wont work - without some overly complicated tricks,
> a shell function is only available within the context/scope of the shell
> or shell script which defines it.  Programs forked by that shell or
> shell script can't exec it because it's not a program as far as they're
> concerned.
> This seems weird and possibly counter-intuitive, but it does make sense.
> It can produce some very unexpected behaviour if you're not used to
> it. 
> My rule of thumb is to only use functions within the context of a
> specific shell script, and not to expect them to be available in
> sub-shells or shell scripts where they haven't been explicitly defined.
> Of course, i could start all shell scripts with something like "source
> ~/myfuncs.sh" but that would be overkill (and ugly!).
> > Anyway, I'd probably try something like this:
> > 
> > find / -size +459976c -noleaf -type f -name '*.deb' -exec split.sh {} \;
> > 
> > #! /bin/sh
> > dpkg-split -s "$1" && rm "$1"
> if you're going to write a script, it's faster to use xargs, that way
> the script only needs to be forked once.
> find / -size +459976c -noleaf -type f -name '*.deb' | xargs split.sh 
> #! /bin/bash
> for pkg in $@ ; do 
>   dpkg-split -s "$pkg" && rm "$pkg"
> done
> split.sh could even be written to take a list of files on stdin and process
> them accordingly.  more effort than what it's worth IMO, let xargs do the
> job :-)

Why not just use

for i in `find / -size +457776c -type f -name '*.deb'` ; do
   dpkg-split -s "$i" && rm "$i"

this gets rid of xargs altogether and seems easier to type as well [as 
long as you get all the quotes and backquotes right.


ps. I don't use bash that much so I hope that this is right, the same 
sort of thing works in rc and I use it frequently.

Reply to: