Probably not as compact as you'd wish...
$ x=( 1 2 3 4 5 6 7 8 9 10 )
$ echo $(( $( printf "+%d" "${x[@]}" ) ))
55
> From: [email protected]
> Date: Fri, 13 Dec 2013 14:53:24 +0100
> To: [email protected]
> Subject: [ast-users] operations on an entire array
>
> 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