Shell Script Calulate Area and Circumference of Circle

by on April 4, 2008 · 4 comments

A circle is one of the simple shapes of Euclidean geometry. It is the locus of all points in a plane at a constant distance, called the radius, from a fixed point, called the center. Through any three points not on the same line, there passes one and only one circle.

A diameter is a chord passing through the center. The length of a diameter is twice the radius. A diameter is the largest chord in a circle.

Circles are simple closed curves which divide the plane into an interior and an exterior. The circumference of a circle is the perimeter of the circle, and the interior of the circle is called a disk.

Sample Shell Script To Calculate Area and Circumference of Circle

  1. #!/bin/bash
  2. # Shell script to calulate area and Circumference of circle.
  3. # It take radius of a circle as input.
  4. # -------------------------------------------------------------------------
  5. # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
  6. # This script is licensed under GNU GPL version 2.0 or above
  7. # -------------------------------------------------------------------------
  8. # This script is part of nixCraft shell script collection (NSSC)
  9. # Visit http://bash.cyberciti.biz/ for more information.
  10. # ----------------------------------------------------------------------
  11. # Lesson on Circumference of a Circle :
  12. # Visit http://www.mathgoodies.com/lessons/vol2/circumference.html
  13. echo -n "Enter the radius of a circle : "
  14. read r
  15.  
  16. # use formula to get it
  17. area=$(echo "scale=2;3.14 * ($r * $r)" | bc)
  18.  
  19. # use formula to get it
  20. d=$(echo "scale=2;2 * $r"|bc)
  21. circumference=$(echo "scale=2;3.14 * $d"| bc)
  22.  
  23. echo "Area of circle is $area"
  24. echo "Circumference of circle is $circumference"


4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • vishnu

    thank for script

  • Sivaranjan

    s there only one data structure in linux…? we cant get the floating point values, like $ for int s ther any for decimal points…?

  • prescia

    Nice explanation and impressive….

  • Na7o0ol

    nice and thank u
    so much
    ilearnt many and make
    a power point for
    cicumference

Previous Script:

Next Script: