Hi, this is Gary with MacMost.com. Let me show you
how to use the Terminal for a better calculator on your Mac.
MacMost is brought to you thanks to a great group of more than 1000 supporters. Go to
MacMost.com/patreon. There you can read more about
the Patreon Campaign. Join us and get exclusive content and course discounts.
Now there are many ways to do calculations on your Mac. For instance you could use the Calculator
and then do basic calculations there. You can use Spotlight and do calculations there. You can use
Siri as well. But if you do a lot of calculations there's another app you should consider. Terminal.
So if you run the Terminal you, of course, have access to the Command Line Interface
and you can do all sorts of things. One of the things you can do is run
Command Line Apps. One of those is the basic calculator or bc. Just type bc and Return and
now you're inside of a calculator app. You just type things, like this, and get the
results. It has all the basic functions so you can do things like this. An Asterisk for
multiplication and a Slash for division and get an answer. You can also use parentheses.
So that makes it a little bit better than the calculator and similar to Spotlight.
Like with calculator you can scroll back to see your previous results. In the Calculator
App that is called Paper Tape. Here it is just something you got in the Terminal window. So
you can scroll back and select Copy and see what you've done. The cool thing you can do
inside of the basic calculator though is you can use Command Line Tool of Up Arrow to go
back to the previous line. So an up arrow goes here and now I can move around in it and Edit
and come up with a different result. I can go back up as many as I want and use
the Down Arrow to go through all the way to the beginning of the list. You can even do
multiple calculations at once. So you could do something like this and then a semi-colon and
then something like this, maybe another semi-colon and then something like this
and get all three answers at once.
There are Variables. So if you're not a programmer you can think of Variables like
the memory function on a calculator except you could have as many as you want. So, for instance,
instead of just typing that you can do a variable name, it could just be a letter, and do that.
Then if you type the variable name you'll see the
contents. It could be a more complex thing. You can do a word like that
and then you can type the whole word to get the result. You can use these
variables inside of calculations. So I can take the two variables I created,
do that, maybe even add something else, and get the result there.
Not only that, but you can also use some standard programming operators. For instance if I were
to use ++ after the number it would give me the result. After it gives me the result it
would add one. So if I look at the value now I can see it's increased. If I put the ++ before
it will add one first and then give me the results. I could also do things like this,
do a plus equals, += like that, and now you can see it added ten. So I could do something where
I said a equal to a number like this and then I could do a+= and then maybe a calculation
and then maybe a+= and another calculation. Then I can get the result stored in there. You could also
use minus equals, -=, multiplication equals *= or divided by equals /=.
Now if you do a calculation like
that and decide you want to store it in a variable later note it is already stored in a variable
called last. So if you want to assign that to a regular variable you could do something like this
b=last and now you've stored it. Or you could have done a+= last to add it to an existing variable.
If you are a programmer this is kind of programmable too.
For instance you can do for loops like this
and then put what you want after it, like that. So I get the number 0 to 9 but, let's
say if I wanted to, you know, do a calculation I could do it like that. Run through a whole set.
Now the one thing you may notice is that if you do a division like this
you just get a whole number as a result. Where are the decimals? Well, let's Quit out of bc and
now let's run bc again but this time with dash L, -l. -l will load the math library which gives you
access to two things. First it gives you access to decimal places. Now regular integers will add
together just fine. But if you do get something that has a remainder, like that, then you get
decimal places. If you want to set the number of decimal places use scale. So scale=2, for
instance, and now I get two decimal places. Using -l also gives you access to math functions. So you
can do things like sine of one half and get sine, co-sine, you know, square root, things like that.
Now if you're saying fine I like the functionality but I don't like the look of using bc in Terminal.
Terminal actually has a whole bunch of different looks. So if we go into Terminal Settings
and we go to Profiles you could see all these cool looks for Terminal Windows. When you want
to create a Terminal Window, if you want to use something else, like let's say use this
second one here, I can go to New Window and choose that. I get this look and, of course,
I can just run bc, maybe -l, like that and now it looks a little different. I could also go
in and customize the settings and set my own up. So let's go to this one, for instance,
and I could click down here and say Duplicate the Profile. I'll call this one bc, because
I'm going to use it with bc, and I can customize how I want things to look. Not only that, but,
if I go to Show here I can have it start up by running a command, like bc-l. You can see
it uses the last command I put there. So now in Terminal I can go New Window and say bc.
It not only styles it like this but runs the bc-l command so I'm ready to do calculations.
Then I can even resize this window. Maybe bc might be nicer if it is a long vertical
window like this. You, of course, can customize fonts, colors, how the cursor looks. All sorts
of things. Then you can set that as your default for Terminal if this is all you use Terminal for.
Terminal even uses Tabs. So if you're doing a bunch of calculations in this Terminal Window
I can do Command T for New Tab and it will open up another Tab, but it is the same profile here
so I can have two separate instances of bc running. So this one could be performing
calculations for one thing and this thing could be preforming calculations for something else.
Now, of course, bc goes even deeper than this. If you want to know everything bc can do type m a n
for manual and then bc. Then you'll receive a full list of everything that bc can do.
There's even a list of the different special variables. There's a list of the different
operators you can use. There's a list of all of the different functions that you could use.
So I think if you do calculations a lot you should give using Basic
Calculator in Terminal a look. There's many advantages over using the Calculator App,
using Spotlight or using Siri on your Mac. I hope you found this useful. Thanks for watching.