Languages
[Edit]
EN

Bash - how to write simple calculator?

13 points
Created by:
AnnLen
1765

Using bash it is possible to write simple calcualtor in following way.

1. In brackets expression example

calcualtor.sh file:

#!/bin/bash

set a b operation;

echo -e "Select operation type: + - * /";
read operation;
echo "a=";
read a;
echo "b="
read b;

echo "Result:" $(($a$operation$b));

Running:

$ ./calculator.sh
Select operation type: + - * /
+
a=
3
b=
6
Result: 9

 

Checkout latest findings & news:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Rockstar community members
Thank you for great work 👍