Re: How to use xargs with a shell redirect



On 13 Apr 2006 08:23:43 -0700
"Joshua Davies" <jdaviestx@xxxxxxxxxxx> wrote:

How can "xargs" (or find with the -exec option) be used to build a
command with redirects in it?

<snip>

This is what I was trying to do:

find . -name "*.iml" | xargs -i -t echo `echo {} | sed -e
's@.*/\(.*\)@\1@'` \>\> `echo {} | sed -e 's@\(.*\)/.*@\1@'`/.cvsignore

I would think that this would do the exact same thing, but it
doesn't... the only reason I can think is because of the attempted
redirect.

Not critical; I got a solution, I just wondered why my "preferred"
solution isn't working (I can't make this work with find -exec,
either).

TIA!


Xargs is not a shell, it doesn't treat characters like ` and > special.
It's job is to start another program repeatedly with the input lines as
arguments. To redirect to different files for different xarg invocations
you need the shell:

find ... | xargs ... sh -c 'script with redirections and other stuff' "$@"

Have a look at the "Single quotes in variable" thread started 9 April.

Magnus
.