Subject: New xargs, was Re: upgrade to mv
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Frederick Bruckman <>
List: tech-userlevel
Date: 08/16/2001 10:14:51
On Wed, 15 Aug 2001, der Mouse wrote:

> > it would mean i could do things like:
> > 	find . -name \*.html -print0 | xargs -0 mv -d otherplace
> The right place to fix this is xargs, not every program you find
> yourself wanting to use with xargs.  I long ago wrote my own xargs
> (largely to get rid of the quoting misfeatures in the stock one) and
> gave it a way to do such things:
>  *      -k<str> indicates that instead of taking the given command and
>  *                arguments and appending the arguments derived from
>  *                the input, xargs should modify and replicate certain
>  *                arguments.  Any argument containing <str> will be
>  *                replicated, once per string,

That looks really useful! I've done

	commands | xargs -n1 sh -c 'command $2 arg arg'

to achieve a similar effect, but it's awkward, and to build it up, you
have to watch the quoting carefully.

>  *      -r<c><s1><c><s2>

This looks like it could be useful, too, but your explanation is
giving me a headache.  :-)

1) I think it would be clearer if it were more like the "sed" manpage,
with plain text for BNF, like


plus a remark that any character can be used for '/', and if

2) the examples would give the exact input, as "echo foo bar baz |
xargs ..."

>  *              indicates that certain argument(s) (or portions
>  *                thereof) to the command are to be replicated.  If
>  *                <s1> appears as an argument to the command, all
>  *                arguments between that and the next argument equal to
>  *                <s2> (or the last argument, if no argument equals
>  *                <s2>) are replicated, appearing once per string.
>  *                (Normally, -k will be used as well, and at least one
>  *                of the replicated arguments will include the -k
>  *                string, but this does not have to be so.)  If an
>  *                argument to the command contains but is not equal to
>  *                <s1>, then part of that argument is replicated.
>  *                Specifically, everything from immediately after the
>  *                <s1>, up to but not including the next <s2> (or the
>  *                end of the argument if there is no following <s2>),
>  *                is replicated.  If -k is used and the replicated
>  *                portion contains the -k string, each copy will have
>  *                the -k string replaced as appropriate.  For example,
>  *
>  *                      xargs -kXX -r/A/B cmd mAjB blivet A -q XX -f mXX B -t
>  *
>  *                will run commands like
>  *
>  *                      cmd mjjj blivet -q foo -f mfoo -q bar -f mbar -q blee -f mblee -t
>  *
>  *                while
>  *
>  *                      xargs -kXX -r/A/B cmd -t mAjXXkB
>  *
>  *                will run commands like
>  *
>  *                      cmd -t mjfookjbarkjbleek
>  *
>  *                Neither <s1> nor <s2> may be zero-length; it is also
>  *                an error for the second <c> to be missing.