Shell Script Calulate Area and Circumference of Circle

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

#!/bin/bash
# Shell script to calulate area and Circumference of circle. 
# It take radius of a circle as input.
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
# Lesson on Circumference of a Circle : 
#  Visit http://www.mathgoodies.com/lessons/vol2/circumference.html
echo -n "Enter the radius of a circle : "
read r
 
# use formula to get it
area=$(echo "scale=2;3.14 * ($r * $r)" | bc)
 
# use formula to get it
d=$(echo "scale=2;2 * $r"|bc)
circumference=$(echo "scale=2;3.14 * $d"| bc)
 
echo "Area of circle is $area"
echo "Circumference of circle is $circumference"
Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
CategoryList of Unix and Linux commands
File Management cat
Firewall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Na7o0ol Feb 29, 2012 @ 14:59

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

  • prescia Jun 25, 2011 @ 11:23

    Nice explanation and impressive….

  • Sivaranjan Feb 21, 2009 @ 11:12

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

  • vishnu Feb 9, 2009 @ 4:15

    thank for script

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.