Quick Command Line Calculator in One Line of Code

Following Jesus; Husband; Father; Developer; Gamer; Tinkerer; Writing about code
Search for a command to run...

Following Jesus; Husband; Father; Developer; Gamer; Tinkerer; Writing about code
No comments yet. Be the first to comment.
Today ChatGPT lied to me, so I’m setting the record straight. This is my question: “If an endpoint in an OpenAPI spec has multiple tags, what will Swagger Codegen do?”. Because Swagger Codegen organized the generated code into api/tag_name_api files....

A Short Story

Universal Libraries, The Internet, and Generative AI

This is the article I wished existed when I needed to support accounting functions. Double-entry Bookkeeping may seem esoteric and unnecessarily complicated, but actually describes a simple framework for maintaining a correctible and auditable record...

How to Change Databases without Downtime

I will admit I'm currently a bit of a complete terminal rat. I use Neovim daily inside of tmux. My tests are run from the terminal. I use git from the terminal. Deploys and releases are done in my terminal. I'll even open web pages with Mac's open command.
So I asked myself: why would I open a separate app to make quick calculations when I have a perfectly good terminal blinking right in front of me? I made a little command to "solve" my "problem" and now I've decided to inflict your eyes with my code. (or checkout the gist)
c() { echo "$@" | bc -l; }
The bc command on its own enters an interactive calculator mode. Which is nice but not what I wanted for quick arithmetic. So I use echo to pipe my calculation ("$@" refers to all the arguments given to this function) into bc and have the results calculated and printed with an immediate return to my normal terminal. For fun I also threw in the -l flag which gives me access to things like sine and cosine (but I cannot say I've really used them). Named it the shortest mnemonic I could think of, c for calculator, and I was done.