A slightly shorter way to do this is
IFS=+
((total=${x[*]}))
unset IFS
On Fri, Dec 13, 2013 at 8:53 AM, Joshua Taylor <[email protected]
> wrote:
> I was wondering if there is some syntax or some method to perform an
> operation (the same operation) on all elements of an array.
>
> for example:
>
> x=( 1 2 3 4 5 6 7 8 9 10 )
>
> is there a shortcut to this:
> ((x[0]+x[1]+x[2]+x[3] ... )) as well as avoiding a for loop?
>
> I had imagined something like x[@]+
>
> Of course, if not, i’ve always got the classic:
> for i in ${x[@]}
> do
> (( total=total+i ))
> done
> _______________________________________________
> ast-users mailing list
> [email protected]
> http://lists.research.att.com/mailman/listinfo/ast-users
>
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users