I was trying to solve this issue using find + xargs but I stuck with another issue
I am try to increasing a count using ((a++)) but not working . I have tried couple of combination of counting a value eg. let a++ a=$[ $a + 1] and so on..
See below Output
rax@ubuntu:~# find ./test/ -mindepth 1 | xargs -I{} -n1 bash -xc "((a++)) ; echo $a {}"
+ (( a++ ))
+ echo 0 ./test/abc1
0 ./test/abc1
+ (( a++ ))
+ echo 0 ./test/abc1/abc
0 ./test/abc1/abc
+ (( a++ ))
+ echo 0 ./test/abc2
0 ./test/abc2
+ (( a++ ))
+ echo 0 ./test/abc3
0 ./test/abc3
+ (( a++ ))
+ echo 0 ./test/abcparent
0 ./test/abcparent
EDIT :- xargs did all in same shell
eg. with pid
rax@ubuntu:~# a=0
rax@ubuntu:~# find ./test/ -mindepth 1 | xargs -L2 -I{} bash -xc "echo $a {} ;((a++)) ; echo $a $$"
+ echo 0 ./test/abc1
0 ./test/abc1
+ (( a++ ))
+ echo 0 1314
0 1314
+ echo 0 ./test/abc1/abc
0 ./test/abc1/abc
+ (( a++ ))
+ echo 0 1314
0 1314
+ echo 0 ./test/abc2
0 ./test/abc2
+ (( a++ ))
+ echo 0 1314
0 1314
+ echo 0 ./test/abc3
0 ./test/abc3
+ (( a++ ))
+ echo 0 1314
0 1314
+ echo 0 ./test/abcparent
0 ./test/abcparent
+ (( a++ ))
+ echo 0 1314
0 1314
find's output towc -lto count the lines of output. – Kyle Jones Apr 04 '13 at 04:28xargs -n1will invoke onebashshell for each line. – Mat Apr 04 '13 at 04:47pid– Rahul Patil Apr 05 '13 at 02:39-n1makes all the difference. (Also note that even in the second case, if there is too much input, you'll get multiple shells.) – Mat Apr 05 '13 at 05:30-Land-n– Rahul Patil Apr 05 '13 at 06:54echo $$– Rahul Patil Apr 05 '13 at 07:27