Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Another way with bash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another way with bash
Authored by: tflight on Feb 02, '05 10:05:34AM
I added the following to my .bash_profile file to accomplish something similar:
function calc () {
        awk "BEGIN { print $* ; }"
}
Then you can bring up the terminal and type things like "calc 9*9" or "calc 3^3" which will return 81 and 27, respectively.

Your .bash_profile file is located in your home directory. In the terminal you can type "cd ~" to make sure you are in your home directory then use a text editor like pico "pico .bash_profile" to edit the file. After saving the file (control-x) you will need to log out and back in for the changes to take effect.

[ Reply to This | # ]

Another way with zsh
Authored by: adrianm on Feb 02, '05 01:43:26PM
if using zsh, try having a function like this

function calc {
  print $(($*))
}
and then you can type, eg calc 9+3

Of course you could also just type print $((9+3)) but that would just spoil the fun.

[ Reply to This | # ]

Another way with csh/tcsh
Authored by: winswitcher429 on Feb 02, '05 03:55:54PM

I have an alias setup in my .cshrc file that looks like this

alias calc 'echo " scale=4;\!*" | bc'

You can then from the command line type in

%calc 5 * 45 + ( 324 - 17 ) / 15
245.4666
%

What's really cool about almost ALL of these hints is that they work on almost ALL Unix versions. I also have this setup on my OpenStep, Solaris and Linux machines and this works that same on all of them



[ Reply to This | # ]