help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Is there a quick way to compute the ratio of two bash ar


From: Greg Wooledge
Subject: Re: [Help-bash] Is there a quick way to compute the ratio of two bash arrays using bc?
Date: Mon, 10 Aug 2015 08:24:35 -0400
User-agent: Mutt/1.4.2.3i

On Sat, Aug 08, 2015 at 11:13:12PM +0200, Geir Hauge wrote:
> Iterate the indices of one of the arrays:
> 
>     r=()
>     for i in "address@hidden"; do
>         r[i]=$(bc -l <<< "${x[i]}/${y[i]}")
>     done

Slightly more efficient would be to launch only one bc(1) process:

mapfile -t r < <(
    for i in "address@hidden"; do
        echo "${x[i]}/${y[i]}"
    done | bc -l
)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]