[Top][All Lists]

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

Re: combine xargs with EOF

From: Greg Wooledge
Subject: Re: combine xargs with EOF
Date: Wed, 17 Oct 2012 14:10:16 -0400
User-agent: Mutt/

On Wed, Oct 17, 2012 at 10:52:37AM -0700, address@hidden wrote:
> find .  -maxdepth 1 -name  '*.txt' -print0  | xargs -n 1 -P 10 bash -c 'echo 
> "$1" '

> do not print $1 so the argument (-n 1)  is not passed inside. 

OK, first thing: you omitted the -0 on xargs.

Next, please realize that I'm not accustomed to this -n -P stuff at all,
so it's not clear what you're trying to accomplish beyond the basic
mechanics of passing the filenames to bash.  You want to print filenames
10 at a time in parallel?  It's a weird question.

If you want the filename to be given as an argument to bash, you actually
need a placeholder after the -c 'script' part.  The first argument after
the script becomes $0, and then the arguments after that become $1, $2, etc.

find .  -maxdepth 1 -name  '*.txt' -print0  |
  xargs -0 -n 1 -P 10 bash -c 'echo "==start $$"; echo "$1"; echo "==end $$"' _

(I added echoes of the start/end of each invoked bash process so I could
see what it's doing.)

reply via email to

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