I'm writing what should be a simple bash script to calculate the minimum value p needs to be in the formula C=1-(p^n). C and p are input by the user and are floating point numbers.
For example if C=0.36 and p=0.8, then my program should return 2 for the value of n, since 1-(0.8^2)=0.36
My code is below. Please note: I have put |bc in many different places in my while loop condition statement and each time I get an error. The last place I tried was, as you can see, between the two closing brackets.
I receive the following error:
operand expected (error token is ".36")
#!/bash/bin
echo "Enter I/O fraction time:"
read ioINPUT
echo "Enter expect CPU utilization:"
read uINPUT
n=1
function cpuUTIL {
x='scale=3; 1-$ioINPUT**$n'|bc
}
while [[ cpuUTIL -lt $uINPUT ]|bc]; do
n+=1
x='scale=3; 1-$ioINPUT**$n'|bc
done
echo $c
How do I properly use bc in a bash script while loop condition statement?
/bash/binspoonerism. 2. Var names should bec,p, andn, not $ioINPUT, $uINPUT, and $x. 3. Last line isecho $c, yet $c is never assigned. 4. Tests an integer-only-ltcomparison with a decimal value. 5. FunctioncpuUTILcan't be tested with-lt. 6. Variable assignments produce no output, so piping them tobchas no effect. 7.]|bc]typo. 8. Thewhiletest wouldn't be affected by what's in that loop, and if started must run forever.