{"id":27754,"date":"2023-11-21T07:34:12","date_gmt":"2023-11-21T07:34:12","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=27754"},"modified":"2024-01-16T08:46:44","modified_gmt":"2024-01-16T08:46:44","slug":"bash-divide","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/","title":{"rendered":"How to Divide Two Numbers in Bash [8 Easy Ways]"},"content":{"rendered":"<p>To <strong>divide two numbers in Bash<\/strong> use the following methods:<\/p>\n<ol>\n<li>Divide two integer variables <strong>x<\/strong> and <strong>y<\/strong> using expr command:<br \/>\n<code class=\"\" data-line=\"\">$(expr $x \/ $y)<\/code><\/li>\n<li>Divide two variables and capture result of division using let command:<br \/>\n<code class=\"\" data-line=\"\">let result=$x\/$y<\/code><\/li>\n<li>Divide two integer numbers using arithmetic expansion:<br \/>\n<code class=\"\" data-line=\"\">$(($x \/ $y))<\/code><\/li>\n<li>Divide two numbers up to desired precision using printf:<br \/>\n<code class=\"\" data-line=\"\">printf &quot;%.&lt;precision&gt;f&quot; $((10**&lt;precision&gt;*$x\/$y))e-&lt;precision&gt;<\/code><\/li>\n<li>Divide floating point numbers using bc command:<br \/>\n<code class=\"\" data-line=\"\">result= &quot;scale=&lt;precision&gt;; $x \/ $y&quot; | bc<\/code><\/li>\n<li>Divide two numbers using awk command:<br \/>\n<code class=\"\" data-line=\"\">$(awk &quot;BEGIN {print $x \/ $y}&quot;)<\/code><\/li>\n<li>Use Python in Bash to divide numbers:<br \/>\n<code class=\"\" data-line=\"\">$(python3 -c &quot;print($x \/ $y)&quot;)<\/code><\/li>\n<li>Perl command for division in Bash:<br \/>\n<code class=\"\" data-line=\"\">$(perl -e &quot;print $x\/$y&quot;)<\/code><\/li>\n<\/ol>\n<p>Now, I am going to discuss each of the above methods in detail. Stay tuned.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Practice-Files_bash-divide.zip\" class=\"su-button su-button-style-default\" style=\"color:#000000;background-color:#E8F9FF;border-color:#bac8cc;border-radius:56px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#000000;padding:8px 26px;font-size:20px;line-height:30px;border-color:#effbff;border-radius:56px;text-shadow:0px 0px 0px #000000\"><i class=\"sui sui-download\" style=\"font-size:20px;color:#1AA1D6\"><\/i> Practice Files of Bash Divide.<\/span><\/a><\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#1_Divide_Two_Variables_Using_the_%E2%80%9Cexpr%E2%80%9D_command\" >1. Divide Two Variables Using the &#8220;expr&#8221; command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#2_Divide_Two_Integer_Numbers_Using_%E2%80%9Clet%E2%80%9D_Command\" >2. Divide Two Integer Numbers Using &#8220;let&#8221; Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#3_Division_of_Two_Numbers_Using_Arithmetic_Expansion\" >3. Division of Two Numbers Using Arithmetic Expansion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#4_Calculating_Division_Up_to_Fixed_Decimal_Points_Using_%E2%80%9Cprintf%E2%80%9D_Command\" >4. Calculating Division Up to Fixed Decimal Points Using &#8220;printf&#8221; Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#5_Division_of_Floating_Point_Numbers_Using_%E2%80%9Cbc%E2%80%9D_Command\" >5. Division of Floating Point Numbers Using &#8220;bc&#8221; Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#6_Divide_Two_Numbers_Using_%E2%80%9Cawk%E2%80%9D_Command\" >6. Divide Two Numbers Using &#8220;awk&#8221; Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#7_Using_Python_Programming_Language\" >7. Using Python Programming Language<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#8_Using_%E2%80%9Cperl%E2%80%9D_Command\" >8. Using &#8220;perl&#8221; Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#How_to_Calculate_Remainder_in_Bash\" >How to Calculate Remainder in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#How_to_Handle_Division_by_Zero_Error_in_Bash\" >How to Handle Division by Zero Error in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#People_Also_Ask\" >People Also Ask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#How_to_round_up_or_floor_the_result_of_division_in_Bash\" >How to round up or floor the result of division in Bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#How_can_I_Divide_a_specific_column_of_numbers_in_Bash\" >How can I Divide a specific column of numbers in Bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#How_to_divide_the_output_of_a_command_in_Bash\" >How to divide the output of a command in Bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#How_do_you_divide_values_in_two_columns_from_different_files_in_Bash\" >How do you divide values in two columns from different files in Bash?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_Divide_Two_Variables_Using_the_%E2%80%9Cexpr%E2%80%9D_command\"><\/span>1. Divide Two Variables Using the &#8220;expr&#8221; command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code class=\"\" data-line=\"\">expr<\/code> command can be used to divide two integer variables. Here\u2019s an example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define variables\nx=10\ny=2\n\n# Use expr to perform division\nresult=$(expr $x \/ $y)\n# Print the result\necho &quot;Result of division: $result&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>This Bash script defines two variables <strong>x<\/strong> and <strong>y<\/strong>, with values <strong>10<\/strong> and <strong>2<\/strong> respectively. It then utilizes the <strong>expr<\/strong> command to perform an integer division of <strong>x <\/strong>by <strong>y<\/strong>.<\/p>\n<\/div><\/div><img decoding=\"async\" class=\"aligncenter size-full wp-image-27771\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.-Dividing-two-variables-using-expr-command.png\" alt=\"Dividing two variables using expr command\" width=\"474\" height=\"105\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.-Dividing-two-variables-using-expr-command.png 474w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.-Dividing-two-variables-using-expr-command-300x66.png 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/>The <strong>expr<\/strong> command, when used for division, provides only the integer portion of the result. For instance, if you divide <strong>5<\/strong> by <strong>2<\/strong>, the expected result is <strong>2.5<\/strong>. However, the <strong>expr<\/strong> command would yield <strong>2<\/strong>.<img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-27772\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.-Result-of-division-while-using-expr-command.png\" alt=\"Result of division while using expr command\" width=\"552\" height=\"119\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.-Result-of-division-while-using-expr-command.png 552w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.-Result-of-division-while-using-expr-command-300x65.png 300w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/>The most important thing to note here is that I have placed a <strong>space before and after <\/strong>the division operator. If you remove these spaces, the <strong>expr <\/strong>command returns the string without performing the division.<img decoding=\"async\" class=\"aligncenter size-full wp-image-27773\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.-Spacing-before-and-after-division-operator-in-expr-command.png\" alt=\"Spacing before and after division operator in expr command\" width=\"517\" height=\"76\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.-Spacing-before-and-after-division-operator-in-expr-command.png 517w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.-Spacing-before-and-after-division-operator-in-expr-command-300x44.png 300w\" sizes=\"(max-width: 517px) 100vw, 517px\" \/>In addition, the<strong> expr<\/strong> command does not support floating point arithmetic. This means that the divisor and the dividend cannot be floating point numbers.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27774\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.-Floating-point-number-issue-in-expr-command.png\" alt=\"Floating point number issue in expr command\" width=\"573\" height=\"140\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.-Floating-point-number-issue-in-expr-command.png 573w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.-Floating-point-number-issue-in-expr-command-300x73.png 300w\" sizes=\"(max-width: 573px) 100vw, 573px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"2_Divide_Two_Integer_Numbers_Using_%E2%80%9Clet%E2%80%9D_Command\"><\/span>2. Divide Two Integer Numbers Using &#8220;let&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code class=\"\" data-line=\"\">let<\/code> command can perform division on the shell variable as well as the variables within the context of the command itself. Let\u2019s see how it performs division on shell variables:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nx=100\ny=25\nlet result=$x\/$y\n# Print the result\necho &quot;Result of division: $result&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>Here, <strong>x=100<\/strong> and <strong>y=25<\/strong>. The <strong>let <\/strong>command divides <strong>x<\/strong> by <strong>y<\/strong> and stores the result of the division in the <strong>result <\/strong>variable.<\/p>\n<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27775\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.-Dividing-two-numbers-using-let-command.png\" alt=\"Dividing two numbers using let command\" width=\"479\" height=\"112\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.-Dividing-two-numbers-using-let-command.png 479w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.-Dividing-two-numbers-using-let-command-300x70.png 300w\" sizes=\"(max-width: 479px) 100vw, 479px\" \/>Upon execution, the result of division <strong>4 <\/strong>is as shown in the above image.<\/p>\n<p>Additionally, variables <strong>x<\/strong> and <strong>y <\/strong>can be set in a single line using the <strong>let <\/strong>command like below:<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27776\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.-Defining-variables-within-let-command.png\" alt=\"Defining variables within let command\" width=\"665\" height=\"140\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.-Defining-variables-within-let-command.png 665w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.-Defining-variables-within-let-command-300x63.png 300w\" sizes=\"(max-width: 665px) 100vw, 665px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"3_Division_of_Two_Numbers_Using_Arithmetic_Expansion\"><\/span>3. Division of Two Numbers Using Arithmetic Expansion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/expansion\/arithmetic-expansion\/\" target=\"_blank\" rel=\"noopener\"><strong>Arithmetic expansion<\/strong><\/a> \u201c$((expression))\u201d can handle arithmetic operations, including division. To divide number <strong>a<\/strong> by <strong>b<\/strong>, use the expression <code class=\"\" data-line=\"\">$((a\/b))<\/code>. Here&#8217;s a simple and clear example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nx=100\ny=25\necho &quot;Result of division: $(($x \/ $y))&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>The script initializes variables <strong>x<\/strong> and<strong> y<\/strong> with values <strong>100<\/strong> and <strong>25<\/strong>, respectively. It then uses <strong>arithmetic expansion<\/strong> to calculate and print the result of dividing<strong> x <\/strong>by<strong> y<\/strong>.<\/p>\n<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27777\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.-Division-using-arithmetic-expansion.png\" alt=\"Division using arithmetic expansion\" width=\"543\" height=\"111\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.-Division-using-arithmetic-expansion.png 543w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.-Division-using-arithmetic-expansion-300x61.png 300w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/>When executed, the script outputs &#8220;Result of division: 4&#8221; to the terminal, representing the division of <strong>100<\/strong> by <strong>25<\/strong>.<\/p>\n<p>Arithmetic expansion provides the integer portion of the result only even if the result of division contains a fraction part. For instance, when <strong>5<\/strong> is divided by <strong>2<\/strong>, it returns <strong>2<\/strong>, not <strong>2.5<\/strong>.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27778\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/8.-Integer-result-of-arithmetic-expansion.png\" alt=\"Integer result of arithmetic expansion\" width=\"477\" height=\"118\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/8.-Integer-result-of-arithmetic-expansion.png 477w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/8.-Integer-result-of-arithmetic-expansion-300x74.png 300w\" sizes=\"(max-width: 477px) 100vw, 477px\" \/><div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#E8F9FC;border-color:#ffffff;color:#333333;\"><strong>NOTE:<\/strong> Arithmetic expansion cannot divide floating point numbers. This means that the divisor, or the dividend, cannot be a floating point number, even if the division result is an integer.<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"4_Calculating_Division_Up_to_Fixed_Decimal_Points_Using_%E2%80%9Cprintf%E2%80%9D_Command\"><\/span>4. Calculating Division Up to Fixed Decimal Points Using &#8220;printf&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code class=\"\" data-line=\"\">printf<\/code> command can be used to get around the limitations of arithmetic expansion. For example, if you divide <strong>5<\/strong> by <strong>2<\/strong>, you won&#8217;t get the whole result of <strong>2.5 <\/strong>using the arithmetic expansion only. However, <strong>printf <\/strong>with format specifier is capable of capturing the result of a division up to certain decimals.<\/p>\n<p>The general syntax is:<br \/>\n<code class=\"\" data-line=\"\">printf &quot;%.&lt;precision&gt;f\\n&quot; $((10**&lt;precision&gt; * &lt;numerator&gt;\/&lt;denominator&gt;))e-&lt;precision&gt;<\/code><br \/>\nLet me explain the syntax using the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">printf &quot;%.2f\\n&quot; $((10**2*5\/2))e-2<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p><strong>$((10**2*5\/2))<\/strong> performs arithmetic expansion. First, 10 raised to the power of 2, which is 100. Then 100 is multiplied by 5, yielding 500. Finally, 500 is divided by 2, resulting in 250.<\/p>\n<p>In <strong>$((10**2*5\/2))e-2<\/strong>, the result of arithmetic expansion is multiplied by e-2. <strong>e-2<\/strong> represents multiplying the preceding value by 10 to the power of -2. In this case, it means dividing the preceding value by 100. So, 250e-2 is equivalent to 2.50.<\/p>\n<p>The <strong>printf &#8220;%.2f\\n&#8221; <\/strong>statement specifies a format for printing. <strong>%.2f<\/strong> specifies that the number should be formatted as a floating point with two decimal places.<\/p>\n<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27779\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/9.-printf-command-for-division-in-bash.png\" alt=\"printf command for division in bash\" width=\"700\" height=\"98\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/9.-printf-command-for-division-in-bash.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/9.-printf-command-for-division-in-bash-300x42.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#E8F9FC;border-color:#ffffff;color:#333333;\"><strong>NOTE: <\/strong>One can specify a precision value in the syntax to print the result up to a specific number of decimals.<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"5_Division_of_Floating_Point_Numbers_Using_%E2%80%9Cbc%E2%80%9D_Command\"><\/span>5. Division of Floating Point Numbers Using &#8220;bc&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you are trying to divide two floating point numbers don\u2019t worry. Here comes the <a href=\"https:\/\/linuxsimply.com\/bc-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>bc command<\/strong><\/a>. This command can divide integers as well as floating-point numbers. For that, you need to write the expression as a string and pass it to the <code class=\"\" data-line=\"\">bc<\/code> command.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nx=100\n$ y=-8.5\nresult= &quot;scale=4; $x \/ $y&quot; | bc\necho &quot;Result of division: $result&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>The variables <strong>x<\/strong> and <strong>y<\/strong> contain values <strong>100<\/strong> and <strong>-8.5<\/strong> respectively. <strong>&#8220;scale=4; $x \/ $y&#8221;<\/strong> indicates a division operation with a precision of <strong>4<\/strong> decimal places. The string is piped to the <strong>bc<\/strong> command, which evaluates the expression and outputs the result. <\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27788\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/10.-bc-command-for-division-in-bash.png\" alt=\"bc command for division in bash\" width=\"489\" height=\"107\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/10.-bc-command-for-division-in-bash.png 489w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/10.-bc-command-for-division-in-bash-300x66.png 300w\" sizes=\"(max-width: 489px) 100vw, 489px\" \/>Upon execution, the program divides <strong>100<\/strong> by <strong>-8.5 <\/strong>and prints the result up to four decimal places which is <strong>-11.7647<\/strong>.<\/p>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#E8F9FC;border-color:#ffffff;color:#333333;\"><strong>NOTE: <\/strong>It is essential to use double quotation marks in the <strong>&#8220;scale=4; $x \/ $y&#8221; <\/strong>statement. Double quotation allows the shell to expand and access variables. On the other hand, a single quotation prevents the shell from expanding variables. Additionally, you can change the scale value to get the division up to the desired number of decimal points.<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"6_Divide_Two_Numbers_Using_%E2%80%9Cawk%E2%80%9D_Command\"><\/span>6. Divide Two Numbers Using &#8220;awk&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <a href=\"https:\/\/linuxsimply.com\/awk-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>awk command<\/strong><\/a> is popular for its text-processing utility. But it also handles arithmetic calculations. To perform division using this command, write the mathematical expression as a string within the BEGIN block, such as &#8220;BEGIN {print 5 \/ 2}&#8221;. Let\u2019s see an example of that:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Define the numbers you want to divide\na=10\nb=3\n\n# Use awk for division\nresult=$(awk &quot;BEGIN {print $a \/ $b}&quot;)\n\n# Print the result\necho &quot;Result of division: $result&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>The program utilizes the <code class=\"\" data-line=\"\">awk<\/code> command to perform division on two numbers, <strong>a<\/strong> and <strong>b<\/strong>. Here, <strong>a<\/strong> is set to 10 and <strong>b<\/strong> is set to 3. The awk command divides the number <strong>a <\/strong>by <strong>b<\/strong> The BEGIN block is used to provide the expression to the awk command.<\/p>\n<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27780\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/11.-awk-command-for-division-in-Bash.png\" alt=\"awk command for division in Bash\" width=\"497\" height=\"111\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/11.-awk-command-for-division-in-Bash.png 497w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/11.-awk-command-for-division-in-Bash-300x67.png 300w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/>As you can see, the program prints the results of division <strong>3.33333 <\/strong>(up to five decimal points by default).<\/p>\n<h2><span class=\"ez-toc-section\" id=\"7_Using_Python_Programming_Language\"><\/span>7. Using Python Programming Language<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>One can use Python for division if it\u2019s already installed in the system. <strong>python2<\/strong> and <strong>python3 <\/strong>commands allow users to use Python version 2 and version 3 functionalities in Bash. Let\u2019s see how to employ Python 3 for division in the Bash shell:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define the numbers\na=10\nb=2\n\n# Perform division using Python\nresult=$(python3 -c &quot;print($a \/ $b)&quot;)\n\n# Print the result\necho &quot;Result of division: $result&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>The program uses Python for the division of two Bash variables <strong>a <\/strong>and <strong>b<\/strong>. The division is performed using the python3. The <strong>-c<\/strong> option allows to run Python utilities. The Python command, &#8220;print($a \/ $b)&#8221;, calculates the result of dividing <strong>a<\/strong> by <strong>b<\/strong>.<\/p>\n<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27781\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/12.-Division-in-Bash-using-Python.png\" alt=\"Division in Bash using Python\" width=\"446\" height=\"121\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/12.-Division-in-Bash-using-Python.png 446w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/12.-Division-in-Bash-using-Python-300x81.png 300w\" sizes=\"(max-width: 446px) 100vw, 446px\" \/>After execution, the program shows that the result of <strong>10<\/strong> divided by <strong>2<\/strong> is <strong>5.0<\/strong>.<\/p>\n<p>Python supports floating point numbers. So numerator and denominator of a division can be floats. Additionally, it allows users to set the precision of the result. Look at the following line of code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">python3 -c &#039;x=20.5; y=2.0; print(&quot;{:.2f}&quot;.format(x\/y))&#039;\n# Output: 10.25<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27782\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/13.-Format-result-of-division-in-Bash.png\" alt=\"Format result of division in Bash\" width=\"825\" height=\"83\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/13.-Format-result-of-division-in-Bash.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/13.-Format-result-of-division-in-Bash-300x30.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/13.-Format-result-of-division-in-Bash-768x77.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p>Here, <code class=\"\" data-line=\"\">&quot;{:.2f}&quot;<\/code> format specifier in <code class=\"\" data-line=\"\">print(&quot;{:.2f}&quot;.format(x\/y)<\/code> used to display the result of x\/y with two decimal places.<\/p>\n<p>Python may not be installed in your system. Run the following command to install python3:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">sudo apt-get install python3<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"8_Using_%E2%80%9Cperl%E2%80%9D_Command\"><\/span>8. Using &#8220;perl&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code class=\"\" data-line=\"\">perl<\/code> one-liner with <code class=\"\" data-line=\"\">-e<\/code> option allows users to perform the division of floating point numbers and customize the precision of the result as needed. Use the following command to do that:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">perl -e &#039;$x=22.0; $y=7.0; printf(&quot;%.6f\\n&quot;, $x\/$y)&#039;<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27783\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/14.-Perl-command-for-division-in-Bash.png\" alt=\"Perl command for division in Bash\" width=\"825\" height=\"87\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/14.-Perl-command-for-division-in-Bash.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/14.-Perl-command-for-division-in-Bash-300x32.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/14.-Perl-command-for-division-in-Bash-768x81.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/>In this example,<code class=\"\" data-line=\"\"> &quot;%.6f\\n&quot;<\/code> is used to format the result of division up to six decimal places. You can adjust the precision by changing the number inside the format specifier.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Calculate_Remainder_in_Bash\"><\/span>How to Calculate Remainder in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The remainder or modulo (<strong>%<\/strong>) operator is used to calculate the remainder of a division in Bash. For example, <code class=\"\" data-line=\"\">$((5%2))<\/code> returns 1 because 5 \/ 2 is 2 with a remainder of 1. Let\u2019s see how it works:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define the numbers\na=10\nb=3\n\n# Calculate remainder\nremainder=$((a % b))\n# Print the result\necho &quot;Remainder of $a divided by $b is: $remainder&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>The script calculates the remainder of dividing the number <strong>a <\/strong>by <strong>b<\/strong> using the modulus operator (<strong>%<\/strong>). The values of <strong>a<\/strong> and <strong>b<\/strong> are defined as <strong>10<\/strong> and <strong>3<\/strong>, respectively. The expression <strong>$((a % b)) <\/strong>computes the remainder of the division.<\/p>\n<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27784\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/15.-Calculating-remainder-in-Bash.png\" alt=\"Calculating remainder in Bash\" width=\"578\" height=\"104\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/15.-Calculating-remainder-in-Bash.png 578w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/15.-Calculating-remainder-in-Bash-300x54.png 300w\" sizes=\"(max-width: 578px) 100vw, 578px\" \/>After running the program, it shows the remainder <strong>1<\/strong> as the remainder of the division 10\/3 is <strong>1<\/strong>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Handle_Division_by_Zero_Error_in_Bash\"><\/span>How to Handle Division by Zero Error in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When performing division, you might not know that the denominator is 0. But in bash, if you&#8217;re dividing by 0, you&#8217;ll get a &#8220;division by 0&#8221; error.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27785\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/16.-Division-by-zero-issue-in-Bash.png\" alt=\"Division by zero issue in Bash\" width=\"700\" height=\"101\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/16.-Division-by-zero-issue-in-Bash.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/16.-Division-by-zero-issue-in-Bash-300x43.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>To handle this error it is wise to check the divisor variable using an if block:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\ndividend=10\ndivisor=0\n# Check if the divisor is zero before performing the division\nif [ $divisor -eq 0 ]; then\necho &quot;Error: Division by zero is not allowed.&quot;\nelse\nresult=$((dividend \/ divisor))\necho &quot;Result: $result&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>The script begins by setting the variables <strong>dividend<\/strong> and <strong>divisor<\/strong> to the values <strong>10<\/strong> and <strong>0<\/strong>, respectively.<\/p>\n<p>It uses the if statement to determine if the divisor is zero. If the divisor is indeed zero, the script outputs a warning message indicating that division by zero is not allowed.<\/p>\n<p>Otherwise, within the else block, the script calculates the result of dividing the dividend by the divisor using the arithmetic expansion and prints the result.<\/p>\n<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27786\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/17.-Checking-division-by-zero-using-if-block.png\" alt=\"Checking division by zero using if block\" width=\"676\" height=\"107\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/17.-Checking-division-by-zero-using-if-block.png 676w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/17.-Checking-division-by-zero-using-if-block-300x47.png 300w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/>Here the dividend is 10 but the divisor is zero. So the warning of the if block is displayed as you can see in the image above.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In conclusion, there are multiple methods available for performing division in Bash. Once you are sufficiently familiar with these methods, you can choose the one that best suits your task. I hope this article helps you understand the different approaches to division in Bash.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_to_round_up_or_floor_the_result_of_division_in_Bash\"><\/span>How to round up or floor the result of division in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>By default arithmetic expansion provides the floored result of a division. For example, The exact result of 7 by 3 is 2.33333&#8230;, but the arithmetic expansion <code class=\"\" data-line=\"\">$((7\/3))<\/code> gives the floored result of 2.<\/p>\n<p>On the other hand, to round up the result add the remainder of the division with the result of the division like the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\"># Example: Divide 10 by 3 and round the result\n#!\/bin\/bash\nx=10\ny=3\nrounded_result=$(( (x \/ y) + (x % y &gt; 0) ))\necho &quot;Rounded Result: $rounded_result&quot;<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_can_I_Divide_a_specific_column_of_numbers_in_Bash\"><\/span>How can I Divide a specific column of numbers in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To <strong>awk<\/strong> command is useful for dividing a particular column of data in a file. Suppose you have a data file named <strong>data.txt<\/strong> with three columns of values. If you wish to divide the numbers in the third column by <strong>1024<\/strong> while keeping the rest of the columns unchanged, you can use the <strong>awk <\/strong>command.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#data.txt\n\n-450\u00a0 1526.64\u00a0 1205.00\n-60.4\u00a0 1507.84\u00a0 1205.36\n15.89\u00a0 1535.96\u00a0 2281.44\n17.89\u00a0 1538.96\u00a0 2281.40\n19.89\u00a0 1542.60\u00a0 2282.08\n21.90\u00a0 1545.96\u00a0 2282.32<\/code><\/pre>\n<p>To do so, use the following code. It processes each line in the file, extracts all fields, divides the third field by 1024, and then prints the formatted result to the terminal:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">awk &#039;{printf &quot;%s\\t%s\\t%.2f\\n&quot;, $1, $2, $3\/1024}&#039; data.txt<\/code><\/pre>\n<p>If you want to replace the original <strong>data.txt <\/strong>file with the modified data, you can use the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">awk &#039;{printf &quot;%s\\t%s\\t%.2f\\n&quot;, $1, $2, $3\/1024}&#039; data.txt &gt; temp &amp;&amp; mv temp data.txt<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_to_divide_the_output_of_a_command_in_Bash\"><\/span>How to divide the output of a command in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To divide the output of a command first capture the output in a variable using command substitution. Then use any methods of division available in Bash. Let\u2019s say you have a file named <strong>file.txt<\/strong>. Now, you want to count the total number of lines in the file and divide it by <strong>2:<\/strong><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">lines= $(cat file | wc -l)\ndiv=$lines\/2\necho &quot;Result: $div&quot;<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_do_you_divide_values_in_two_columns_from_different_files_in_Bash\"><\/span>How do you divide values in two columns from different files in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To divide the values of two columns from different files, you can use a combination of commands such as <strong>paste<\/strong> or <strong>awk<\/strong>. Here&#8217;s an example assuming two files, <strong>file1.txt <\/strong>and <strong>file2.txt<\/strong>, with values arranged in a column:<br \/>\n<strong>#file1.txt<\/strong><br \/>\n<strong>10.2<\/strong><br \/>\n<strong>20<\/strong><br \/>\n<strong>11.5<\/strong><br \/>\n<strong>#file2.txt<\/strong><br \/>\n<strong>9<\/strong><br \/>\n<strong>5<\/strong><br \/>\n<strong>3.33<\/strong><br \/>\nNow divide the values of <strong>file1.txt<\/strong> by the values of <strong>file2.txt<\/strong> using the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">result=$(paste file1.txt file2.txt | awk &#039;{printf &quot;%.2f\\n&quot;, $1\/$2}&#039;)\necho &quot;Result: $result&quot;<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27787\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/18.-Calculating-division-of-values-from-two-different-files.png\" alt=\"Calculating division of values from two different files\" width=\"825\" height=\"114\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/18.-Calculating-division-of-values-from-two-different-files.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/18.-Calculating-division-of-values-from-two-different-files-300x41.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/18.-Calculating-division-of-values-from-two-different-files-768x106.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/>This command uses <a href=\"https:\/\/linuxsimply.com\/paste-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>paste<\/strong><\/a> to merge the two files side by side and then uses <strong>awk<\/strong> to perform the division operation.<\/p>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/math-in-bash\/\" target=\"_blank\" rel=\"noopener\">Performing Math Operations in Bash [12+ Commands Explained]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/calculate\/\" target=\"_blank\" rel=\"noopener\">How to Calculate in Bash [3 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/\" target=\"_blank\" rel=\"noopener\">How to Sum Up Numbers in Bash [Explained With Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/floating-point-division\/\" target=\"_blank\" rel=\"noopener\">Division of Floating Point Numbers in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/mod\/\" target=\"_blank\" rel=\"noopener\">How to Use &#8220;Mod&#8221; Operator in Bash [5 Basic Usage]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/format-number\/\" target=\"_blank\" rel=\"noopener\">How to Format Number in Bash [6 Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/random-number\/\" target=\"_blank\" rel=\"noopener\">How to Generate Random Number in Bash [7 Easy Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/hex-to-decimal\/\" target=\"_blank\" rel=\"noopener\">How to Convert Hexadecimal Number to Decimal in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/binary-operator-expected\/\" target=\"_blank\" rel=\"noopener\">[Solved] \u201cbinary operator expected\u201d Error in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/integer-expression-expected\/\" target=\"_blank\" rel=\"noopener\">[Fixed] \u201cinteger expression expected\u201d Error in Bash<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Arithmetic Operators in Bash&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/\" target=\"_blank\" rel=\"noopener\">Arithmetic Operators in Bash<\/a><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Operator&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/\" target=\"_blank\" rel=\"noopener\">Bash Operator<\/a><\/span> | <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/strong><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;27754&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Divide Two Numbers in Bash [8 Easy Ways]&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>To divide two numbers in Bash use the following methods: Divide two integer variables x and y using expr command: &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Divide Two Numbers in Bash [8 Easy Ways]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#more-27754\" aria-label=\"Read more about How to Divide Two Numbers in Bash [8 Easy Ways]\">Read more<\/a><\/p>\n","protected":false},"author":314903,"featured_media":27789,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[170],"class_list":["post-27754","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-arithmetic-operators","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Divide Two Numbers in Bash [8 Easy Ways] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"There are multiple ways to divide numbers in Bash. This article talks about those ways with clear and useful examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Divide Two Numbers in Bash [8 Easy Ways] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"There are multiple ways to divide numbers in Bash. This article talks about those ways with clear and useful examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/zahidlaku72\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-21T07:34:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-16T08:46:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/How-to-Divide-Numbers-in-Bash.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Md Zahidul Islam Laku\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Md Zahidul Islam Laku\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/\"},\"author\":{\"name\":\"Md Zahidul Islam Laku\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\"},\"headline\":\"How to Divide Two Numbers in Bash [8 Easy Ways]\",\"datePublished\":\"2023-11-21T07:34:12+00:00\",\"dateModified\":\"2024-01-16T08:46:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/\"},\"wordCount\":2068,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/How-to-Divide-Numbers-in-Bash.png\",\"keywords\":[\"arithmetic operators\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/\",\"name\":\"How to Divide Two Numbers in Bash [8 Easy Ways] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/How-to-Divide-Numbers-in-Bash.png\",\"datePublished\":\"2023-11-21T07:34:12+00:00\",\"dateModified\":\"2024-01-16T08:46:44+00:00\",\"description\":\"There are multiple ways to divide numbers in Bash. This article talks about those ways with clear and useful examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/How-to-Divide-Numbers-in-Bash.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/How-to-Divide-Numbers-in-Bash.png\",\"width\":400,\"height\":400,\"caption\":\"How to Divide Numbers in Bash\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/divide\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash Operator\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Arithmetic Operators in Bash\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Divide Two Numbers in Bash [8 Easy Ways]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\",\"name\":\"Md Zahidul Islam Laku\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"caption\":\"Md Zahidul Islam Laku\"},\"description\":\"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/zahidlaku72\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/zahidlaku\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCnxMIaAb-nXO5XnMeEaNhpQ\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/laku\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Divide Two Numbers in Bash [8 Easy Ways] - LinuxSimply","description":"There are multiple ways to divide numbers in Bash. This article talks about those ways with clear and useful examples.","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:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/","og_locale":"en_US","og_type":"article","og_title":"How to Divide Two Numbers in Bash [8 Easy Ways] - LinuxSimply","og_description":"There are multiple ways to divide numbers in Bash. This article talks about those ways with clear and useful examples.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/zahidlaku72","article_published_time":"2023-11-21T07:34:12+00:00","article_modified_time":"2024-01-16T08:46:44+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/How-to-Divide-Numbers-in-Bash.png","type":"image\/png"}],"author":"Md Zahidul Islam Laku","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Md Zahidul Islam Laku","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/"},"author":{"name":"Md Zahidul Islam Laku","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21"},"headline":"How to Divide Two Numbers in Bash [8 Easy Ways]","datePublished":"2023-11-21T07:34:12+00:00","dateModified":"2024-01-16T08:46:44+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/"},"wordCount":2068,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/How-to-Divide-Numbers-in-Bash.png","keywords":["arithmetic operators"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/","name":"How to Divide Two Numbers in Bash [8 Easy Ways] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/How-to-Divide-Numbers-in-Bash.png","datePublished":"2023-11-21T07:34:12+00:00","dateModified":"2024-01-16T08:46:44+00:00","description":"There are multiple ways to divide numbers in Bash. This article talks about those ways with clear and useful examples.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/How-to-Divide-Numbers-in-Bash.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/How-to-Divide-Numbers-in-Bash.png","width":400,"height":400,"caption":"How to Divide Numbers in Bash"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/divide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},{"@type":"ListItem","position":3,"name":"Bash Operator","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/"},{"@type":"ListItem","position":4,"name":"Arithmetic Operators in Bash","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/"},{"@type":"ListItem","position":5,"name":"How to Divide Two Numbers in Bash [8 Easy Ways]"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21","name":"Md Zahidul Islam Laku","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","caption":"Md Zahidul Islam Laku"},"description":"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio","sameAs":["https:\/\/www.facebook.com\/zahidlaku72","https:\/\/www.linkedin.com\/in\/zahidlaku\/","https:\/\/www.youtube.com\/channel\/UCnxMIaAb-nXO5XnMeEaNhpQ"],"url":"https:\/\/linuxsimply.com\/author\/laku\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/27754","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314903"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=27754"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/27754\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/27789"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=27754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=27754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=27754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}