Multiplication of array elements

Hi,

I can't find out how to create correct code to get multiplication of each elements of array. Let's say I enter array into command line (2 3 4 5 6 8) and i need output 2*3*4*5*6*8=5760.

I tried this one, but answer is 0.

for i in $@; do
mult=$((mult*i))done
echo "mult: " $mult

Guys, please help :slight_smile:

Got a recent bash ? Try

line=(2 3 4 5 6 8) 
echo $(($(IFS="*"; echo "${line
[*]}")))
5760

Perfect. Thank you very much.

or set to mult to 1 (initial value)

mult=1
for i in $@; do
mult=$((mult*i)) ; done
echo "mult: " $mult

and/or...

mult=1
for i
do
    mult=$((mult*i))
done
IFS="*"
echo "$@=$mult"

$ ./func 1 2 3 4 5 6 8
1*2*3*4*5*6*8=5760