{
  "path": "/posts/2013/2013-07-05-qc",
  "site": "at://did:plc:mracrip6qu3vw46nbewg44sm/site.standard.publication/self",
  "tags": [
    "code",
    "python",
    "bash"
  ],
  "$type": "site.standard.document",
  "title": "qc: quick calculator",
  "updatedAt": "2013-07-05T00:00:00.000Z",
  "publishedAt": "2013-07-05T00:00:00.000Z",
  "textContent": "If you spend most of your time in the command line, you don't want to leave to do math. Qc is a script that does in-line command line math without forcing you to exit the main bash prompt as you might with a program like bc or a language interpreter.\n\nMake the script executable with the command:\n\nAlias it to qc by editing the .bash_profile file in your home folder and adding the code:\n\nUse qc as follows:\n\nIn reality, this script is just a glorified alias of python -c, but importing the math library makes this command considerably more powerful.\n\nThis wildcard import gives access to constants such as pi and e in calculations, but more notably, it also allows for the use of functions in calculations. For example:\n\nBecause qc is executed in bash, it requires quotes (single or double) to be placed around expressions with functions, since bash will try to evaluate expressions in parentheses before it does anything else. The quotes tell bash to pass the entire expression as a whole to qc instead of trying to evaluate part of it beforehand.\n\nFinally, once you have the result of a calculation, the pbcopy command places the result in the clipboard for ease of use.\n\nOn Linux, a few lines of python will accomplish the same task.\n\nEdit 7/23: changed eval to evaluated in the code to avoid conflict with the bash builtin.\n\nThe script determines which copy commands to use based on your OS. The full script is available on Github.",
  "canonicalUrl": "https://www.danielcorin.com/posts/2013/2013-07-05-qc"
}