|
| From: | Chris F.A. Johnson |
| Subject: | Re: [Help-bash] Is there a quick way to compute the ratio of two bash arrays using bc?for n in "address@hidden" |
| Date: | Sat, 8 Aug 2015 17:16:01 -0400 (EDT) |
| User-agent: | Alpine 2.10 (DEB 1266 2009-07-14) |
On Sat, 8 Aug 2015, Peng Yu wrote:
Hi, I'd like to compute the ratios of two bash arrays. When there are
just 2 elements in each array, I simply do the following as it is the
quickest to type.
r=(
$(bc -l <<< ${x[0]}/${y[0]})
$(bc -l <<< ${x[1]}/${y[1]})
)
When there are more elements, does anybody has a better way to do it?
for n in "address@hidden" doprintf "%s/%s\n" "${x[n]}" "${y[n]}" done | bc -l
-- Chris F.A. Johnson, <http://cfajohnson.com>
| [Prev in Thread] | Current Thread | [Next in Thread] |