Showing posts with label add numbers in bash. Show all posts
Showing posts with label add numbers in bash. Show all posts

Wednesday, September 3, 2014

Addition of Five Numbers in Bash

One of the interesting aspects of open source software is that we can explore different types of tools and programming languages that can help us in our everyday work. When I started learning Linux way back in 2010 I can say it is a different experience first time in my life I was able to learn an operating system that is free, open source, stable and best of all has many built in functions that cannot be found in windows operating system. At first I found myself in a difficult situation because of lacking of experience in Linux and there are only few books written on that particular subjects. The biggest hindrance for beginners like me how to learn the rules in using Linux in everyday computing activities.

The best advice that I get actually is the forum that I read in the Internet the journey in Linux or Unix operating system is a step by step process. Read a lot from blogs, tutorials and articles in the Internet and do some example activities in your computer by installing virtual machine or install the full installation of the operating in your computer. It takes a lot of courage and confidence to learn something new in this ever changing world of Information Technology. By persistence, hard work and patience your effort spend in learning Linux is a worth while.

In this article I would like to share with you my avid reader of my blog of the simplest script that I have written using BASH script of Bourne Again Shell I called this program addition of five numbers. What the program will do is to ask the user to enter five numbers and then it will compute for the sum of five numbers being given by our user. I am using Ubuntu 14.04 as my Linux distribution, I try to improve myself in the aspect of scripting programming using BASH because it is very useful in system administration of networks.

If you find my work useful let me know kindly send me an email at jakerpomperada@yahoo. com and jakerpomperada@gmail.com.

Thank you very much.

 Nano text editor used in writing this BASH script.


Change File Permission and Running our BASH script.

Sample Output of Our Program


Program Listing

#!/bin/bash

# addition.sh
# addition of five numbers in bash
# written by: Mr. Jake  R. Pomperada, MAED-IT
# tools : Ubuntu 14.04
# date  : September 03, 2014

clear
echo -e "\n"
echo -e "\t (===== Addition of Five Numbers =====)"
echo -e "\n"
read -p  "Enter First Number   :  " a
read -p  "Enter Second Number  :  " b
read -p  "Enter Third Number   :  " c
read -p  "Enter Fourth Number  :  " d
read -p  "Enter Fifth Number   :  " e

sum=$(expr "$a" + "$b" + "$c" + "$d" + "$e")

echo -e "\n"
echo "The sum of  $a, $b, $c, $d and $c is $sum.";
echo -e "\n"
echo -e "\t Thank you for using program."
echo -e "\n"