Shell-Implemented Calculators

Source: Internet
Author: User
Tags function calculator


1 #!/bin/bash

2 #FUNCTION Calculator

3 #AUTHOR Wangbo

4 #DATE 2015-09-26

5

6

7 function Checknum ()

8 {

9 Expr + 0 &>/dev/null

10

Case $? Inch

12 0)

return $

14;;

15 *)

16

Read-t 50-p "Please input integer:" int

18

Check "$int"

20

Return "$int"

22

23;;

Esac

25}

26

function operate ()

28 {

echo "$"

If ["$" = = "+"]

Then

echo "$ (($1$2$3))"

-Fi

If ["$" = "-"]

Then

echo "$ (($1$2$3))"

Panax Notoginseng fi

If ["$" = "*"]

About

echo "DDD"

echo "$ (($1$2$3))"

Fi

If ["$" = = "/"]

Then

echo "$ (($1$2$3))"

-Fi

47}

48

#get first number from user

Read-t 50-p "Please input first number:" First

51

Checknum "$first"

53

#get First Number

Fnum=$?

56

Operate #get

Read-t 50-p "Please input first operate (+-*/):" Operate

59

#get second number from user

Read-t 50-p "Please input second number:" Second

62

Checknum "$second"

64

#get Second Number

Snum=$?

67

#print result

69

Operate $fnum $operate $snum


This article is from the Shell Implementation Calculator blog, so be sure to keep this source http://codekong.blog.51cto.com/10704076/1699616

Shell-Implemented Calculators

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.