On Fri, Dec 13, 2013 at 9:53 PM, 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 usually do like this:
$ a=(1 2 3 4 5 6 7 8 9 10)
$ s=${a[*]}
$ echo $(( ${s// /+} ))
55
$
>
> 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