These Unix Spotlights are about some Unix commands that you might not know exist and a few things you can do with them.
bc is a calculator.
One of my favorite commands is
bc -l because I'm terrible at arithmetic. The
l (lowercase L) flag allows you to "use the predefined math routines"; practically, this means you get non-integer division and some sweet functions you can use. I'd recommend always using
bc -l over
$ bc -l # It has some copyright stuff here. > 22 - (13 / 2) 15.50000000000000000000 > quit
>'s here for my input in
Sweet. Note that to get out of
bc you type the word
quit and it'll take you back to the shell.
What else can you do with
bc? If you wanted the FULL EXPERIENCE you could do a whole lot of crazy wild calculations and some programming stuff but you're probably better off doing those in your Language Of Choice™ or checking out Wolfram Alpha. But here's a few quick things I use in
# Square roots sqrt(2) 1.41421356237309504880 # Natural log l(10) 2.30258509299404568401 # Exponential e(10) 22026.46579480671651695790 # Sine, input in radians s(3.141592/2) .99999999999994660254 # Cosine, input in radians c(3.141592/2) .00000032679489661922
One annoying thing is that constants like $e$ and $\pi$ aren't defined, but it's still pretty okay if you need a basic approximation of something.