Real number in while loop in bash -
i while loop in bash, using real numbers, gives me errors. whatever try , find on internet doesn't fix problem.
here problematic part of code: (energy find command energy=$(echo "$real1 - $real2" | bc -l)
energy=${energy#-} deltae=$(echo "$energy" | bc -l) echo $energy echo $deltae while (( $deltae > 0.0001 ));
of course there after "do" execution stops here. gives me following error :
1.999655175151897025 1.999655175151897025 ./run_ilda.sh: line 99: ((: 1.999655175151897025 > 0.0001 : syntax error: invalid arithmetic operator (error token ".999655175151897025 > 0.0001 ")
and without $ :
while (( deltae > 0.0001 ));
it gives
1.999655175151897025 1.999655175151897025 ./run_ilda.sh: line 99: ((: 1.999655175151897025: syntax error: invalid arithmetic operator (error token ".999655175151897025")
i tried :
while [ $deltae -gt 0.0001 ]
and gives me :
1.999655175151897025 1.999655175151897025 ./run_ilda.sh: line 99: [: 1.999655175151897025: integer expression expected
does know what's going on , how fix this?
use bc evaluate comparison:
if (( $(echo "$deltae > 0.0001" | bc -l) )); ... fi
Comments
Post a Comment