On Wed, Oct 17, 2012 at 10:52:37AM -0700, giuseppe.amatu...@gmail.com 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.
So:

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