<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knowledge Base (Posts about calculator)</title><link>https://bgstack15.ddns.net/blog/</link><description></description><atom:link href="https://bgstack15.ddns.net/blog/categories/calculator.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2022 &lt;a href="mailto:bgstack15@gmail.com"&gt;bgstack15&lt;/a&gt; 
&lt;a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
style="border-width:0; margin-bottom:12px;"
src="https://bgstack15.ddns.net/.images/l_by-sa_4.0_88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Sun, 27 Feb 2022 04:05:04 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Save settings for bc, the Linux calculator</title><link>https://bgstack15.ddns.net/blog/posts/2017/09/14/save-settings-for-bc-the-linux-calculator/</link><dc:creator>bgstack15</dc:creator><description>&lt;h2&gt;tl;dr&lt;/h2&gt;
&lt;p&gt;Use a ~/.bcrc file with contents:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;scale=4
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Execute this or put it in your bashrc:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="n"&gt;BC_ENV_ARGS&lt;/span&gt;&lt;span class="o"&gt;=~/.&lt;/span&gt;&lt;span class="n"&gt;bcrc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Explanation&lt;/h2&gt;
&lt;p&gt;In GNU/Linux, a basic calculator is &lt;strong&gt;bc&lt;/strong&gt; from package bc. The normal output
is displayed with zero values after the decimal point, so I like to adjust it
to show me four numerals past the decimal point.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;scale=4
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can use whatever scale you like. To get this to take effect every time you
call bc, you can set an environment variable BC_ENV_ARGS to a filename. That
file is parsed as regular instructions to bc, before it enters the interactive
shell or interprets standard in. So modify a file, such as ~/.bcrc with your
instructions. Update your shell (or add to your .bashrc file):&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bcrc&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="n"&gt;BC_ENV_ARGS&lt;/span&gt;&lt;span class="o"&gt;=~/.&lt;/span&gt;&lt;span class="n"&gt;bcrc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;References&lt;/h2&gt;
&lt;h3&gt;Weblinks&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Inspiration for this post &lt;a href="http://linux.byexamples.com/archives/42/command-line-calculator-bc/"&gt;http://linux.byexamples.com/archives/42/command-line-calculator-bc/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Description of "rc" files in Unix &lt;a href="https://en.wikipedia.org/wiki/Run_commands"&gt;https://en.wikipedia.org/wiki/Run_commands&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;man pages&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://linux.die.net/man/1/bc"&gt;bc&lt;/a&gt;&lt;/p&gt;</description><category>bc</category><category>calculator</category><category>cli</category><guid>https://bgstack15.ddns.net/blog/posts/2017/09/14/save-settings-for-bc-the-linux-calculator/</guid><pubDate>Thu, 14 Sep 2017 13:25:55 GMT</pubDate></item></channel></rss>