David Pease <dpease@davisvision.com> wrote:
> $ echo 1 |xargs -ip echo $[ p ] p
> 0 1
>
> Is this the correct behavior?
Yes. The arithmetic expansion is done by bash before xargs is
executed. $p is presumably not set, so $[p] is 0. You can see the
arguments actually seen by xargs like this:
$ bash -xc 'echo 1 | xargs -ip echo $[ p ] p'
+ echo 1
+ xargs -ip echo 0 p
0 1
Here's how you could get the behavior you want:
echo 1 | xargs -n 1 bash -c 'echo $[$0] $0'
paul