bc is cool, but it can not access shell variables directly, but you can pass them with <<<
also there is no “pi” constant in bc that you could use in interactive mode.
let one assume you would like to calculate extend “umfang” of a circle with radius 5
the formula
Extend/Umfang U = 2 · π · r
the bash
pi=$(echo "scale=10; 4*a(1)" | bc -l); # calc value of pi 10 digits and store it in variable $pi echo $pi; # test output 3.1415926532 bc <<< "scale=10 ; 2*$pi*5"; # do the calculation 31.4159265320
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!