

{"id":111278,"date":"2023-01-21T10:00:17","date_gmt":"2023-01-21T04:30:17","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=111278"},"modified":"2023-01-21T10:01:36","modified_gmt":"2023-01-21T04:31:36","slug":"bc-command-in-linux","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/","title":{"rendered":"bc Command in Linux"},"content":{"rendered":"<p>In this article, we will learn everything about the bc command in Linux. We will look at what the bc command is, its purpose, the syntax of the bc command, the options used along with the command, and the operators supported by the bc command. We will also look at a practical example in the terminal of Ubuntu 20.04 for each type of operator to understand their functioning.<\/p>\n<h3>What is Linux bc command?<\/h3>\n<p>Bc is a command-line-based utility in Linux and Unix-based operating systems used as a calculator. Calling the bc command a &#8220;calculator&#8221; somewhat makes it look naive and basic, but the bc command is capable of complex numerical, which consist of various numbers and operators. It can even handle interactive statements like for loop.<\/p>\n<p>When we say calculator, we think of the calculator on the GUI of your computer, but the calculator in the terminal is far superior. Apart from solving your day-to-day arithmetic tasks, the bc command can also do things like algebra, handling variables, converting numbers to hexadecimal, iterative statements, conditional statements, math functions, and more.<\/p>\n<p>In a nutshell, the bc command is a command-line advanced scientific calculator. We generally use the bc command by piping it with the echo command, as the output will be passed in as the input for the bc command.<\/p>\n<h3>Syntax of bc command in Linux<\/h3>\n<p>The syntax of the bc command is extremely easy. See for yourself:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">bc &lt;options&gt; &lt;filename&gt;<\/pre>\n<h3>Options used along with the bc command<\/h3>\n<p>Unlike most of the commands in Linux, the bc command has only a few options associated with it. Let us take a brief look at each one of them:<\/p>\n<p><strong>1. -h<\/strong><\/p>\n<p>This option prints the help menu of the bc command, as shown below:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/help-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111546\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/help-1.webp\" alt=\"help\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<p><strong>2. -i<\/strong><\/p>\n<p>This option forces the bc command to interactive mode. You can also write this option as &#8220;&#8211;interactive.&#8221;<\/p>\n<p><strong>3. -l<\/strong><\/p>\n<p>This option defined the standard math library. You can also write this option as &#8220;&#8211;mathlib.&#8221;<\/p>\n<p><strong>4. -w<\/strong><\/p>\n<p>This option gives warnings for extensions to POSIX bc. You can also write this option as &#8220;&#8211;warn.&#8221;<\/p>\n<p><strong>5. -s<\/strong><\/p>\n<p>This option processes the POSIX bc language. You can also write this option as &#8220;&#8211;standard.&#8221;<\/p>\n<p><strong>6. -q<\/strong><\/p>\n<p>This option does not print the normal GNU bc welcome. You can also write this option as &#8220;&#8211;quiet.&#8221;<\/p>\n<p><strong>7. -v<\/strong><\/p>\n<p>This option prints the information about the version of the bc command:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/version-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111547\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/version-1.webp\" alt=\"version\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h3>Features of bc command in Linux<\/h3>\n<p>Remember that we touch on some of the many great and superior features of the bc command, well here is the complete list of the features the bc command supports:<\/p>\n<p>1. Arithmetic operators<br \/>\n2. Increment or Decrement operators<br \/>\n3. Assignment operators<br \/>\n4. Relational operators<br \/>\n5. Logical or Boolean operators<br \/>\n6. Math functions<br \/>\n7. Conditional statements<br \/>\n8. Iterative statements<\/p>\n<p>Let us look at each of the features in slightly more detail, along with some examples, to understand them better.<\/p>\n<h4>1. Linux Arithmetic operators<\/h4>\n<p>Arithmetic operators consist of basic daily math problems involving addition, subtraction, division, multiplication, exponents, and modulus division. To perform such operations, all you have to do is to pipe the bc command with an echo command which contains the problem. Use the syntax shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">echo \u201c&lt;num1&gt; &lt;operator&gt; &lt;num2&gt;\u201d | bc<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/arithmetic.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111548\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/arithmetic.webp\" alt=\"arithmetic\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<p><strong>Storing a value in a variable<\/strong><\/p>\n<p>Remember that I told you that the bc command could handle variables? Well, it can, but how do we store a value in a variable? We simply put the variables in front of the echo command, and when we want to print the answer, we call the variable using the echo command by preceding it with a dollar sign. Use the syntax shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;variable&gt;=`echo \u201c&lt;num1&gt; &lt;operator&gt; &lt;num2&gt;\u201d | bc`\r\necho $&lt;variable&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/storing-value.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111552\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/storing-value.webp\" alt=\"storing value\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h4>2. Assignment operators in Linux<\/h4>\n<p>Assignment operators are more like a shortcut for writing long arithmetic numerals. Let us look at them to get a better idea of how they work:<\/p>\n<p>1. variable = value: assigning a value to a variable<br \/>\n2. variable += value : same as (variable = variable + value)<br \/>\n3. variable -= value :same as (variable = variable \u2013 value)<br \/>\n4. variable *= value : same as (variable = variable * value)<br \/>\n5. variable \/= value : same as (variable = variable \/ value)<br \/>\n6. variable ^= value : same as (variable = variable ^ value)<br \/>\n7. variable %= value : same as (variable = variable % value)<\/p>\n<p><strong>Note<\/strong>: we can combine multiple echo statements by simply separating them by a semicolon (;)<\/p>\n<p>Let us look at an example for each of the seven assignment variables to understand their working better.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/assignment.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111553\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/assignment.webp\" alt=\"assignment\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h4>3. Linux Increment and decrement operators<\/h4>\n<p>Increment operators are also another way of writing arithmetic numerical in short notation. Let us look at them to get a better idea of how they work:<\/p>\n<p><strong>a. variable++<\/strong><\/p>\n<p>The increment operator is the same as (variable=variable+1) or (variable+=1). This operator is called the post-increment operator, as the variable result<strong> is used first, and then the variable is incremented.<\/strong><\/p>\n<p><strong>b. ++variable<\/strong><\/p>\n<p>The increment operator is the same as (variable=variable+1) or (variable+=1). You must be wondering, as this is similar to the &#8220;variable++&#8221; operator. Well, there is one key difference &#8211; this operator is called the pre-increment operator, as the variable is increased first, and then the variable result is stored.<\/p>\n<p><strong>c. variable&#8211;<\/strong><\/p>\n<p>The increment operator is the same as (variable=variable-1) or (variable-=1). This operator is called the post-decrement operator, as the variable result is used first, and then the variable is decreased.<\/p>\n<p><strong>d. &#8211;variable<\/strong><\/p>\n<p>The increment operator is the same as (variable=variable-1) or (variable-=1). Therefore, you might think this is similar to the &#8220;variable&#8211;&#8221; operator. However, there is one key difference &#8211; This operator is called the pre-decrement operator, as the variable is decreased first, and then the variable result is stored.<\/p>\n<p>Let us look at an example for each of the four assignment variables to understand their working better.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/increment-decrement.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111554\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/increment-decrement.webp\" alt=\"increment decrement\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h4>4. Linux Relational operators<\/h4>\n<p>Relational operators are used for comparing two numbers. If it is true, the result is 1. Otherwise (if the comparison is true), the result is 0. Let us look at them to get a better idea of how they work:<\/p>\n<p>1. expr1&lt;expr2 : Outputs 1 if expr1 is less than expr2.<br \/>\n2. expr1&lt;=expr2 : Outputs 1 if expr1 is less than or equal to expr2.<br \/>\n3. expr1&gt;expr2 : Outputs 1 if expr1 is greater than expr2.<br \/>\n4. expr1&gt;=expr2 : Outputs 1 if expr1 is greater than or equal to expr2.<br \/>\n5. expr1==expr2 : Outputs 1 if expr1 is equal to expr2.<br \/>\n6. expr1!=expr2 : Outputs 1 if expr1 is not equal to expr2.<\/p>\n<p>Let us look at an example for each of the six assignment variables to understand their working better.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/relational.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111555\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/relational.webp\" alt=\"relational\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h4><span style=\"font-weight: 400\">5. Linux Logical operators<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Logical operators are slightly more intimidating. Thankfully there are only a few of them. We will be mainly focusing on: &#8220;Logical and&#8221;, &#8220;Logical or&#8221;, and &#8220;Logical negation (!)&#8221;. These are used to club two or more relational statements to narrow down the condition even more. Let us look at how these work before we see an example.<\/span><\/p>\n<p><strong>a. Logical and operator (&amp;&amp;)\u00a0<\/strong><\/p>\n<p><span style=\"font-weight: 400\">The &#8220;logical and operator&#8221; will be true if the conditions are true. If not, it will be false, meaning it will be false if any one or both of the conditions are true. It is denoted by two ampersand symbols (&amp;&amp;). To understand this operator better, let us look at the truth table enclosed with different scenarios:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>NO<\/strong><\/td>\n<td><strong>CONDITION\u00a0 1<\/strong><\/td>\n<td><strong>CONDITION 2<\/strong><\/td>\n<td><strong>CONDITION\u00a0 1 &amp;&amp; CONDITION\u00a0 2<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400\">Let us now look at the above table in form of an example to understand this operator fully:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/logical.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111557\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/logical.webp\" alt=\"logical\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<p><strong>b. Logical or operator (||)\u00a0<\/strong><\/p>\n<p><span style=\"font-weight: 400\">The &#8220;logical or operator&#8221; will be <\/span><b>true if any one of the conditions is true, and <\/b><span style=\"font-weight: 400\">it will be false if both the conditions are false. It is denoted by two pipe symbols (||). To understand this operator better, let us look at the truth table enclosed with different scenarios:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>NO<\/strong><\/td>\n<td><strong>CONDITION\u00a0 1<\/strong><\/td>\n<td><strong>CONDITION 2<\/strong><\/td>\n<td><strong>CONDITION\u00a0 1 || CONDITION\u00a0 2<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE (1)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE (0)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400\">Let us now look at the above table as an example to understand this operator fully!<\/span><\/p>\n<p><strong>c. Logical negation (!)\u00a0<\/strong><\/p>\n<p><span style=\"font-weight: 400\">This operator is pretty simple. It simply inverts the truth value, and if it is true, it will become false, and vice versa:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>NO<\/strong><\/td>\n<td><strong>CONDITION\u00a0\u00a0<\/strong><\/td>\n<td><span style=\"font-weight: 400\"><strong>! CONDITION<\/strong>\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">FALSE<\/span><\/td>\n<td><span style=\"font-weight: 400\">TRUE<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400\">Let us now look at the above table in form of an example to understand this operator fully:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/logical-negation.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111558\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/logical-negation.webp\" alt=\"logical negation\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h4>6. Linux Mathematical functions<\/h4>\n<p>The bc command also has many in-built maths functions. Let us look at what they are and their uses.<\/p>\n<p>1. s (x): The sine of x, the value of x is in radians.<br \/>\n2. c (x): The cosine of x, the value of x is in radians.<br \/>\n3. a (x): The arctangent of x, arctangent returns radians.<br \/>\n4. l (x): The natural logarithm of x.<br \/>\n5. e (x): The exponential function of raising e to the value x.<br \/>\n6. j (n,x) : The Bessel function of integer order n of x.<br \/>\n7. sqrt(x) : Square root of the number x.<br \/>\n8. length(x) : Returns the number of digits in x.<br \/>\n9. read(): Reads the number from the standard input.<br \/>\n10. scale(expression): The value of the scale function is the number of digits after the decimal point in the expression.<br \/>\n11. ibase and obase: Used to convert decimal to binary and vice versa<br \/>\n12. last (an extension): is a variable with the value of the last printed number.<\/p>\n<p>Let us look at some examples of these math functions in action to understand better how they work.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/mathematical.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111559\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/mathematical.webp\" alt=\"mathematical\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h4>7. Linux Conditional statements<\/h4>\n<p>Conditional statements are nothing but if-else statements. They are used to make decisions and execute statements based on these decisions. It means that if the conditions are true, it will execute a specific set of statements, and if the conditions are false, it will execute another set of statements. The syntax of the if statement is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if(condition) {statements} else {statements}\r\n\r\nif(condition) {statements} else {statements}<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/conditional.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111560\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/conditional.webp\" alt=\"conditional\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h4>8. Linux Iterative statements<\/h4>\n<p>Loops or iterative statements repeat a set of statements until the conditions specified are false. The bc command supports the for loop and while loop. The for loop syntax is: for(assignment; condition; update) {statments}<\/p>\n<p>The while loop syntax is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">while(condition){statments}<\/pre>\n<p>Here is an example of printing numbers 1 to 10 using both for loop and while loop:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/iterative.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111563\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/iterative.webp\" alt=\"iterative\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/while.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111564\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/while.webp\" alt=\"while\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<p>While using conditional statements and iterative statements, we sometimes use a few pseudo statements when a certain condition is met. Let us look at the pseudo statements supported by the bc command.<\/p>\n<p><strong>a. Break<\/strong><\/p>\n<p>This statement causes a forced exit of the most recent enclosing while statement or for statement.<\/p>\n<p><strong>b. Continue<\/strong><\/p>\n<p>This statement causes the most recent enclosing statement to start the next iteration.<\/p>\n<p><strong>c. halt<\/strong><\/p>\n<p>This statement is an executed statement that causes the bc processor to quit only when it is executed.<\/p>\n<p><strong>d. return<\/strong><\/p>\n<p>Return the value 0 from a function. (See the section on functions).<\/p>\n<p><strong>e. return(expression)<\/strong><\/p>\n<p>This statement returns the value of the expression from a function.<\/p>\n<p><strong>f. limits<\/strong><\/p>\n<p>This statement prints the local limits enforced by the local version of bc.<\/p>\n<p><strong>g. quit<\/strong><\/p>\n<p>This statement terminates the bc processor.<\/p>\n<p><strong>h. warranty<\/strong><\/p>\n<p>This statement prints a warranty notice.<\/p>\n<h3>Functions in Linux<\/h3>\n<p>The bc command also supports functions. Functions are one of the most powerful tools for any programming language, as you can choose what happens in your custom-made function. Once you have built your function, you can call it where you want it with the appropriate input and get the desired output. The syntax for writing a function is shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">define &lt;function name&gt;(parameters) \r\n{\r\n        statements...\r\n        .....................\r\n        return statement\r\n}\r\n\r\n<\/pre>\n<h3>Using Linux bc command with a file<\/h3>\n<p>In the syntax of the bc command, we have a field called &lt;filename&gt;. What exactly is this for? We can write our arithmetic operations in a file and then use the bc command followed by the filename to execute our text file.<\/p>\n<p>We first use the cat command along with a redirection operator to write our problems and then use the bc command followed by the filename. Here is an example illustrating the same:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/example.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111565\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/example.webp\" alt=\"example\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<p>We have gotten our desired output, but there is one tiny problem &#8211; the bc command prints unnecessary messages. To avoid printing this, pair the bc command with the option &#8220;-q,&#8221; as shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">bc -q &lt;filename&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/pair.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-111566\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/pair.webp\" alt=\"pair\" width=\"1280\" height=\"412\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>As you have seen, the bc command is far more than a calculator. It is simple yet advanced for it to be compared to the awk command &#8211; a one-line scripting command. You have now understood what the bc command is, its purpose, the syntax of the command, the options used, and the various features supported by the bc command. We have explored each operator and feature with the help of at least one example to provide us with a better picture of its working.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will learn everything about the bc command in Linux. We will look at what the bc command is, its purpose, the syntax of the bc command, the options used along&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":111506,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[27201,27202],"class_list":["post-111278","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-bc-command-in-linux","tag-linux-bc-options"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>bc Command in Linux - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about Linux bc command, its purpose, syntax of the command, the options used, and the various features supported by the bc command.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"bc Command in Linux - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about Linux bc command, its purpose, syntax of the command, the options used, and the various features supported by the bc command.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-21T04:30:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-21T04:31:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/bc-command-in-linux.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"bc Command in Linux - DataFlair","description":"Learn about Linux bc command, its purpose, syntax of the command, the options used, and the various features supported by the bc command.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"bc Command in Linux - DataFlair","og_description":"Learn about Linux bc command, its purpose, syntax of the command, the options used, and the various features supported by the bc command.","og_url":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-01-21T04:30:17+00:00","article_modified_time":"2023-01-21T04:31:36+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/bc-command-in-linux.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"bc Command in Linux","datePublished":"2023-01-21T04:30:17+00:00","dateModified":"2023-01-21T04:31:36+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/"},"wordCount":2040,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/bc-command-in-linux.webp","keywords":["bc Command in Linux","linux bc options"],"articleSection":["Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/","url":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/","name":"bc Command in Linux - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/bc-command-in-linux.webp","datePublished":"2023-01-21T04:30:17+00:00","dateModified":"2023-01-21T04:31:36+00:00","description":"Learn about Linux bc command, its purpose, syntax of the command, the options used, and the various features supported by the bc command.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/bc-command-in-linux.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/01\/bc-command-in-linux.webp","width":1200,"height":628,"caption":"bc command in linux"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/bc-command-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Linux Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/linux\/"},{"@type":"ListItem","position":3,"name":"bc Command in Linux"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/111278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=111278"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/111278\/revisions"}],"predecessor-version":[{"id":111567,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/111278\/revisions\/111567"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/111506"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=111278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=111278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=111278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}