Coding Villa

Quick Calculator Function for Terminal

Author : Zaryab Liaqat

Share with Friends
Views : 372
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


Here we are going to tell you that how you can create the calculator function for the Terminal and if you will go through this article you will see that creating calculator function is so simple with the help of Bash shell.


Advertisements


 

Yu know that question mark is use to run the bc command and its does not matter what you write after that. 

 

Creating the Terminal Calculator Function

Now to create the calculator function you need to write this line in the Terminal

? () { echo "$*" | bc -l; }

Now accessing of it is very simple just you need to type ? And then math equation depends on your calculations. You can use the spaces but for that you need to use quotes around the statement otherwise you will see the error like this:

 

 

If there is Cygwin is installed in your system then you can use it also on the window. For that purpose there should be bc package installed.

 

 

Here you can see the use of bc command.

Making the Function Save across Restarts

If there is  Linux  or Cygwin in windows then first you have to edit this file and then type this line at bottom.

vi ~/.bash_profile

 

Now close the terminal and then reopen it then you will see that the command is enabled.

 

 

 

Saving the Function in OS X

If there is  OS X  in your system then you just need to open the Terminal and then type this,

Touch .profile

Open .profile

Now at this step you should be at default folder that is user folder for the new Terminal window.

 

 

To open the file you just need to type open command which will open .profile file in Textedit at there you can past in the line, save and close.

 

 

Now close the Terminal, reopen and you can see the function available.

 



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook