Unix Shell - How sum 2 arrays in ksh ?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > How sum 2 arrays in ksh ?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How sum 2 arrays in ksh ?
apogeusistemas@gmail.com

2007-12-09, 1:25 pm

Hi:
I need sum a[1] + b[1] to result "4", but why these commands doesn't
do that ?

# a="1 2 3"
# b="3 4 5"
# c=${a[1]}+${b[1]}
# echo $c
+
#

Thanks
Janis Papanagnou

2007-12-09, 1:25 pm

apogeusistemas@gmail.com wrote:
> Hi:
> I need sum a[1] + b[1] to result "4", but why these commands doesn't
> do that ?
>
> # a="1 2 3"
> # b="3 4 5"
> # c=${a[1]}+${b[1]}
> # echo $c
> +
> #
>
> Thanks


a=( 1 2 3 )
b=( 3 4 5 )
c=$(( a[1] + b[1] ))
echo $c

Mind that the result is "6" because array indexes start at 0.

Janis
Bobby.Higgins

2007-12-29, 1:28 pm

$ set -A a 1 2 3
$ set -A b 3 4 5
$ echo $(( a[0] + b[0] ))
4

<apogeusistemas@gmail.com> wrote in message
news:b81e5800-64dd-40cb-868e-ed3c6fe08d9f@d27g2000prf.googlegroups.com...
> Hi:
> I need sum a[1] + b[1] to result "4", but why these commands doesn't
> do that ?
>
> # a="1 2 3"
> # b="3 4 5"
> # c=${a[1]}+${b[1]}
> # echo $c
> +
> #
>
> Thanks



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com