How do I get the value in parentheses?

#!/bin/bash

z=`echo "$a*(1+($p/(100*$g)))^((($j)+($m/12)+($t/365))*$g)" | wcalc -EE`
y=`echo read$z/$k^2 | wcalc`
echo $y

      

My second line does the collation $z/($k^2)

, but I need ($z/$k)^2

how to do it?

+3


source to share


1 answer


The problem, as I understand it, is that it is z

not a number, but something like a form = 1.2345

(that is, the line with =

before the number). I think the best way to make this work is to make the number a z

number. Unfortunately, wcalc

it doesn't seem to have the option to do this, so I resort to using awk

:

#                                                  here, at the end ------v
z=`echo "$a*(1+($p/(100*$g)))^((($j)+($m/12)+($t/365))*$g)" | wcalc -EE | awk '{ print $2 }'`
y=`echo "read = ($z/$k)^2" | wcalc` # and perhaps apply a similar transformation here.
echo "$y"

      



Note that it wcalc

does not remember the assignment read

, though, because the process ends immediately. I don't know what you want to achieve.

+3


source







All Articles