20 January 2012

Shell Script to add two numbers by the use of Function

13 comments

Q. How do I write Bash Script to add two numbers using function


Ans:

#!/bin/bash
#function to add two numbers
add()
{
x=$1
y=$2
echo -e "Number entered by u are: $x and $y"
echo "sum of $1 and $2 is `expr $x + $y` "
}
# main script
echo "enter first number"
read first
echo "enter second number"
read sec
#calling function
add $first $sec
echo "end of the script"

Output


shell script to add two numbers using function

Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

13 comments:

  1. Thnx its gud who want to learn shell schripting as well as programming basics

    ReplyDelete
  2. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    python course in pune
    python course in chennai
    python Training in Bangalore

    ReplyDelete
  3. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    rpa training in bangalore
    best rpa training in bangalore
    rpa training in pune | rpa course in bangalore
    rpa training in chennai

    ReplyDelete
  4. This post is so interactive and informative.keep update more information...
    Android Training in Anna Nagar
    Android Training in Chennai

    ReplyDelete
  5. This post is so interactive and informative.keep update more information...
    DevOps course in Tambaram
    DevOps Training in Chennai

    ReplyDelete
  6. Thank you for sharing this insightful content. I always appreciate reading such high-quality information. The presented ideas are truly outstanding and captivating, making the post a delight to explore. Your fantastic work is commendable – keep it up.
    visit: Getting To Know Test Automation: Navigating Tools And Frameworks For Software Testing Excellence

    ReplyDelete
  7. Thanks admin for sharing this I like this.If you want to know about Java so you can visit: Java Performance Tuning: Optimizing Your Code for Speed

    ReplyDelete
  8. great post, impressive , the way you explain shell-script-to-add-two-numbers-by-use is hats off , no doubt getting high demands in IT is java , and your looking for it then visit java course in pune , thanks for this valuable post

    ReplyDelete
  9. Thank you for sharing. I always appreciate engaging content with valuable insights. The presented ideas are exceptional and innovative, making the post truly enjoyable. Keep up the fantastic work.

    Visit site: Data Magic: Python's Role In The Age Of Analytics

    ReplyDelete
  10. Informative post. Thank you sharing. Please visit our website to learn new courses.

    ReplyDelete