bug-findutils
[Top][All Lists]
Advanced

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

Re: ls * | xargs --counter=^ --replace=_ "echo argument number ^ is _"


From: James Youngman
Subject: Re: ls * | xargs --counter=^ --replace=_ "echo argument number ^ is _"
Date: Sun, 2 Jun 2013 14:50:39 +0100

On Wed, Jan 25, 2012 at 6:38 PM, Lars Thon <address@hidden> wrote:
> xargs wishlist item:
>
> a method for accessing an xargs running argument count so that the
> count can be used in the command to be executed by xargs:
>
> For example, the syntax could be as follows:
>
> ls * | xargs --counter=^ --replace=_ "echo argument number ^ is _"
>
> The counter should perhaps be 0-based, or 1-based, or N-based (programmable
> initial value).

But if that's what you want to do, why use xargs at all?

$ ( set -- $(echo *); count=0; for arg; do echo "Argument ${count} is
${arg}"; (( ++count )); done )
Argument 0 is build-aux
Argument 1 is config.cache
Argument 2 is config.h
Argument 3 is config.log
Argument 4 is config.status
Argument 5 is doc
Argument 6 is find
Argument 7 is gl
Argument 8 is GNUmakefile
Argument 9 is lib
Argument 10 is locate
Argument 11 is m4
Argument 12 is Makefile
Argument 13 is po
Argument 14 is stamp-h1
Argument 15 is tests
Argument 16 is xargs

$ awk 'BEGIN {for (i=1; i<ARGC; ++i) { printf("Argument %d is %s\n",
i, ARGV[i]); }; exit(0); }' *
Argument 1 is build-aux
Argument 2 is config.cache
Argument 3 is config.h
Argument 4 is config.log
Argument 5 is config.status
Argument 6 is doc
Argument 7 is find
Argument 8 is gl
Argument 9 is GNUmakefile
Argument 10 is lib
Argument 11 is locate
Argument 12 is m4
Argument 13 is Makefile
Argument 14 is po
Argument 15 is stamp-h1
Argument 16 is tests
Argument 17 is xargs



reply via email to

[Prev in Thread] Current Thread [Next in Thread]