{"id":27354,"date":"2023-11-16T11:15:07","date_gmt":"2023-11-16T11:15:07","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=27354"},"modified":"2024-05-04T14:19:40","modified_gmt":"2024-05-04T14:19:40","slug":"bash-sum-numbers","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/","title":{"rendered":"How to Sum Up Numbers in Bash [Explained With Examples]"},"content":{"rendered":"<p style=\"text-align: justify;\">Adding numbers is one of the basic math operations one needs to perform. In the Bash shell, there are a couple of ways to add two or multiple numbers. It\u2019s important to note that the Bash shell primarily performs integer arithmetics. For the addition of floating point numbers commands such as the <strong>bc<\/strong> or <strong>awk<\/strong> are quite useful. In this article, I will discuss different commands and techniques to sum up numbers in Bash shell.<\/p>\n<div class=\"su-youtube su-u-responsive-media-yes\"><iframe width=\"600\" height=\"400\" src=\"https:\/\/www.youtube.com\/embed\/WRj5TiWiPzM?\" frameborder=\"0\" allowfullscreen allow=\"autoplay; encrypted-media; picture-in-picture\" title=\"\"><\/iframe><\/div>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Practice-Files_bash-sum-numbers.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 for Sum of Numbers in Bash<\/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\/sum-numbers\/#Integer_and_Floating_Point_Numbers\" >Integer and Floating Point Numbers<\/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\/sum-numbers\/#1_Sum_Up_Integer_Numbers\" >1. Sum Up Integer Numbers<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#A_Using_the_%E2%80%98declare_Command\" >A. Using the \u2018declare\u2019 Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#B_Using_Arithmetic_Expansion\" >B. Using Arithmetic Expansion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#C_Sum_Up_Integer_Elements_of_an_Array_Using_%E2%80%98expr_Command\" >C. Sum Up Integer Elements of an Array Using \u2018expr\u2019 Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#D_Utilizing_the_%E2%80%98let_Command\" >D. Utilizing the \u2018let\u2019 Command<\/a><\/li><\/ul><\/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\/sum-numbers\/#2_Sum_Up_Float_or_Double_Type_Numbers_Using_%E2%80%98bc_Command\" >2. Sum Up Float or Double Type Numbers Using \u2018bc\u2019 Command<\/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\/sum-numbers\/#How_to_Sum_Up_Numbers_From_a_File_in_Bash\" >How to Sum Up Numbers From a File in Bash?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#A_Sum_a_Column_of_Integer_Numbers_From_a_File_in_Bash\" >A. Sum a Column of Integer Numbers From a File in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#B_Sum_a_Column_of_Floating_Point_Numbers_From_a_File\" >B. Sum a Column of Floating Point Numbers From a File<\/a><\/li><\/ul><\/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\/sum-numbers\/#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\/sum-numbers\/#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\/sum-numbers\/#How_to_find_the_sum_of_a_string_of_numbers_in_Bash\" >How to find the sum of a string 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-14\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#How_to_add_numbers_from_two_files_simultaneously\" >How to add numbers from two files simultaneously?<\/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\/sum-numbers\/#How_to_increment_a_variable_by_one_in_Bash\" >How to increment a variable by one 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\/sum-numbers\/#How_to_perform_a_column-wise_sum_of_numbers_from_a_file\" >How to perform a column-wise sum of numbers from a file?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Integer_and_Floating_Point_Numbers\"><\/span>Integer and Floating Point Numbers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Integer numbers such as <strong>1<\/strong>, <strong>5<\/strong>, <strong>10,<\/strong> etc. are easy to handle using Bash <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/expansion\/arithmetic-expansion\/\" target=\"_blank\" rel=\"noopener\"><strong>arithmetic expansion<\/strong><\/a>. On the other hand, floating-point numbers for example <strong>1.6<\/strong>, <strong>10.5<\/strong>, <strong>4.4<\/strong>, etc can not be added using simple arithmetic expansion. Fortunately, there are multiple commands for working with floating point numbers in Bash.<\/p>\n<p style=\"text-align: justify;\">In the following section, I will show how you can add integer and floating-point numbers using different methods.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"1_Sum_Up_Integer_Numbers\"><\/span>1. Sum Up Integer Numbers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">There are several ways to sum up integer numbers. The shell built-in <strong>declare<\/strong> command, <strong>arithmetic expansion,<\/strong> and the <strong>expr<\/strong> command are names of a few. First, let\u2019s talk about the use of the declare command to perform arithmetic addition:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"A_Using_the_%E2%80%98declare_Command\"><\/span>A. Using the \u2018declare\u2019 Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In Bash, one can declare a variable as an integer using the <a href=\"https:\/\/linuxsimply.com\/declare-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>declare command<\/strong><\/a> with its option<strong> -i<\/strong>. This option tells bash to treat the variable as an integer. Look at the following commands:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">declare -i A=2+8\necho $A<\/code><\/pre>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-27357\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.-Declare-command-to-sum-numbers-in-Bash.png\" alt=\"Declare command to sum numbers in Bash\" width=\"522\" height=\"143\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.-Declare-command-to-sum-numbers-in-Bash.png 522w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.-Declare-command-to-sum-numbers-in-Bash-300x82.png 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/>Here the <strong>declare<\/strong> command sums up <strong>2 <\/strong>and <strong>8<\/strong>, resulting in <strong>10<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"B_Using_Arithmetic_Expansion\"><\/span>B. Using Arithmetic Expansion<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To sum up two numbers using <strong>arithmetic expansion<\/strong>, enclose the numbers within an arithmetic expansion. For instance, to add <strong>5<\/strong> and <strong>8<\/strong>, use the expression <strong>$((5 + 8))<\/strong>. Bash shell can successfully evaluate such expressions. For example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define the two numbers\nread -p &quot;Enter the first number: &quot; num1\nread -p &quot;Enter the second number: &quot; num2\n\n# Calculate the sum\nsum=$((num1 + num2))\n\n# Display the result\necho &quot;The sum of $num1 and $num2 is: $sum&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 style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">read<\/code> command prompts (with <strong>option -p<\/strong>) the user to input the numbers for summation. Then the script uses the <strong>addition <\/strong>(<strong>+<\/strong>) operator in arithmetic expansion to add the values of <strong>num1<\/strong> and <strong>num2<\/strong>.<\/div><\/div><img decoding=\"async\" class=\"aligncenter size-full wp-image-27358\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.-Arithmetic-expansion-to-sum-numbers-in-Bash.png\" alt=\"Arithmetic expansion to sum numbers in Bash\" width=\"489\" height=\"178\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.-Arithmetic-expansion-to-sum-numbers-in-Bash.png 489w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.-Arithmetic-expansion-to-sum-numbers-in-Bash-300x109.png 300w\" sizes=\"(max-width: 489px) 100vw, 489px\" \/>The program adds <strong>10 <\/strong>and <strong>15<\/strong> provided by the user and shows the result <strong>25 <\/strong>as you can see in the image above.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"C_Sum_Up_Integer_Elements_of_an_Array_Using_%E2%80%98expr_Command\"><\/span>C. Sum Up Integer Elements of an Array Using \u2018expr\u2019 Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Another command is expr which is capable of adding integers. Here I will show you how to use this command to sum up integer elements of an array. To sum up the elements of an array, first, expand the array. Then iterate through each element and add them to a variable. Essentially, the variable contains the summation of all the elements of the array. See the below script to learn how it works:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define an array of numbers\nnumbers=(2 5 8 3 6 9 4 7 10)\nsum=$(expr 0)\nfor num in &quot;${numbers[@]}&quot;; do\nsum=$(expr $sum + $num)\ndone\n\n# Display the result\necho &quot;The sum of the numbers is: $sum&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 style=\"text-align: justify;\"><code class=\"\" data-line=\"\">$(expr $sum + $num)<\/code> adds a single element with the <code class=\"\" data-line=\"\">sum<\/code> variable. The for loop accumulates the summation of all elements of the <code class=\"\" data-line=\"\">numbers<\/code> array in <code class=\"\" data-line=\"\">sum<\/code>.<\/div><\/div><img decoding=\"async\" class=\"aligncenter size-full wp-image-27359\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.-expr-command-to-sum-up-array-element-in-Bash.png\" alt=\"expr command to sum up array element in Bash\" width=\"502\" height=\"110\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.-expr-command-to-sum-up-array-element-in-Bash.png 502w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.-expr-command-to-sum-up-array-element-in-Bash-300x66.png 300w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/>The program sums up the elements of the array <code class=\"\" data-line=\"\">(2 5 8 3 6 9 4 7 10)<\/code>. The result of the addition <strong>54 <\/strong>is displayed in the terminal.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"D_Utilizing_the_%E2%80%98let_Command\"><\/span>D. Utilizing the \u2018let\u2019 Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong>let<\/strong> command enables users to carry out arithmetic addition with minimal syntax. For instance, the expression <code class=\"\" data-line=\"\">let sum=num1+num2<\/code> captures the result of adding the variables <code class=\"\" data-line=\"\">num1<\/code> and <code class=\"\" data-line=\"\">num2<\/code>. Check the process through the following process:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define integers\nnum1=10\nnum2=12\n\n# Use let for arithmetic expansion to calculate the sum\nlet &quot;sum = num1 + num2&quot;\n\n# Display the result\necho &quot;The sum of $num1 and $num2 is: $sum&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 style=\"text-align: justify;\">In the script, <code class=\"\" data-line=\"\">let &quot;sum = num1 + num2&quot;<\/code> perform arithmetic addition. The <strong>let<\/strong> command adds the values stored in the variables <strong>num1<\/strong> and <strong>num2<\/strong>. The result of this addition is then assigned to the variable sum.<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27360\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.-let-command-to-sum-integer-numbers-in-Bash.png\" alt=\" let command to sum integer numbers in Bash\" width=\"457\" height=\"110\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.-let-command-to-sum-integer-numbers-in-Bash.png 457w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.-let-command-to-sum-integer-numbers-in-Bash-300x72.png 300w\" sizes=\"(max-width: 457px) 100vw, 457px\" \/>In the above code, the value of <strong>num1<\/strong> is <strong>10<\/strong>, and the value of <strong>num2<\/strong> is <strong>22<\/strong>. Upon execution, the result of addition <strong>22<\/strong> is displayed as you can see in the image.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"2_Sum_Up_Float_or_Double_Type_Numbers_Using_%E2%80%98bc_Command\"><\/span>2. Sum Up Float or Double Type Numbers Using \u2018bc\u2019 Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To add float or double-type numbers first write the math expression using the <a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a>. Then, pass the expression to the <a href=\"https:\/\/linuxsimply.com\/bc-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>bc<\/strong> <strong>command<\/strong><\/a> to evaluate. Let\u2019s say you want to sum up <strong>3.5<\/strong> and <strong>2.5<\/strong>. You can write the expression using <code class=\"\" data-line=\"\">echo &quot;3.5 + 2.5&quot;<\/code>. After that, you need to pass it to the <strong>bc<\/strong> command using a <strong>pipe<\/strong>. See the script below to get a clear idea:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define the two floating-point numbers\nread -p &quot;Enter the first number: &quot; num1\nread -p &quot;Enter the second number: &quot; num2\n\n# Use bc to calculate the sum\nsum=$(echo &quot;$num1 + $num2&quot; | bc)\n\n# Display the result\necho &quot;The sum of $num1 and $num2 is: $sum&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 style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">read<\/code> command prompts the user to input the numbers for summation. The script uses the <strong>echo<\/strong> command to write an expression <code class=\"\" data-line=\"\">&quot;$num1 + $num2&quot;<\/code> and pass it to the <strong>bc <\/strong>command for evaluation using a <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/redirection-and-piping\/piping\/\" target=\"_blank\" rel=\"noopener\"><strong>pipe<\/strong> (<strong>|<\/strong>)<\/a> operator.<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27361\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.-Sum-up-floating-point-numbers-in-Bash.png\" alt=\"Sum up floating point numbers in Bash\" width=\"554\" height=\"180\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.-Sum-up-floating-point-numbers-in-Bash.png 554w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.-Sum-up-floating-point-numbers-in-Bash-300x97.png 300w\" sizes=\"(max-width: 554px) 100vw, 554px\" \/>Here you can see the program successfully adds <strong>10.5<\/strong> and <strong>2.9 <\/strong>and prints the result of addition <strong>13.4<\/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;\">\n<p style=\"text-align: justify;\">The <a href=\"https:\/\/linuxsimply.com\/awk-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>awk<\/strong> <strong>command<\/strong><\/a>\u00a0is also useful for adding floating-point numbers. For example, when you input <code class=\"\" data-line=\"\">echo 12.8 12.2 | awk &#039;{print $1 + $2}&#039;<\/code>, it calculates the sum of <strong>12.8<\/strong> and <strong>12.2<\/strong> and displays the result <strong>25 <\/strong>in the terminal. <\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Sum_Up_Numbers_From_a_File_in_Bash\"><\/span>How to Sum Up Numbers From a File in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">It is often necessary to sum numbers from a file. In most cases, these numbers are arranged in columns. Now, I will demonstrate how to add numbers from a file, both for integer and floating-point values:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"A_Sum_a_Column_of_Integer_Numbers_From_a_File_in_Bash\"><\/span>A. Sum a Column of Integer Numbers From a File in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">One can add a column of numbers from a file using the <strong>awk<\/strong> command. This command can extract any field from each line of a file. For example, <strong>$2<\/strong> and <strong>$3 <\/strong>extract the second and third fields of a line. Let&#8217;s consider column data like below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\"># numbers.txt\n4\n10\n15<\/code><\/pre>\n<p style=\"text-align: justify;\"><strong>$1<\/strong> in <strong>awk<\/strong> command can extract the first field <strong>4<\/strong> from the first line and the first field <strong>10<\/strong> from the second line and so on. This way <strong>awk <\/strong>can accumulate all the numbers of the column. Let\u2019s see a practical example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Use awk to sum each column\nsum_col=$(awk &#039;{sum+=$1} END {print sum}&#039; &quot;numbers.txt&quot;\n\n# Display the results\necho &quot;Sum of Column: $sum_col&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 style=\"text-align: justify;\">The program uses the <code class=\"\" data-line=\"\">awk<\/code> command to sum up the column of numbers from the <strong>numbers.txt<\/strong> file. It sums up the column of numbers using the <code class=\"\" data-line=\"\">&#039;{sum+=$1} END {print sum}&#039;<\/code>. Here, the <strong>sum <\/strong>variable accumulates the sum of the first column, and the <strong>END<\/strong> block prints the final sum.<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27362\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.-Sum-up-columns-of-numbers-from-a-file.png\" alt=\"Sum up columns of numbers from a file\" width=\"497\" height=\"300\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.-Sum-up-columns-of-numbers-from-a-file.png 497w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.-Sum-up-columns-of-numbers-from-a-file-300x181.png 300w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/>First, you can see the cat command displays that the <strong>numbers.txt<\/strong> file contains a column of numbers. Then after execution, the script adds all these numbers from <strong>15 <\/strong>to <strong>6 <\/strong>and prints the result of addition which is <strong>36<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"B_Sum_a_Column_of_Floating_Point_Numbers_From_a_File\"><\/span>B. Sum a Column of Floating Point Numbers From a File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Column-wise arranged numbers of a file may contain floating points. One can add these numbers in many ways. I will show you a very compact way to sum up using the <strong>perl <\/strong>command. Consider a file containing numbers like below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\"># float.txt\n4.5\n10.1\n15.4<\/code><\/pre>\n<p>To add the numbers of the float.txt file use the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nperl -lne &#039;$sum += $_; END { print $sum }&#039; float.txt<\/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 style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">perl<\/code> command sums up a column of floating-point numbers from the file named <strong>float.txt<\/strong>. The <code class=\"\" data-line=\"\">-l<\/code> option ensures proper handling of newlines. The script increments the <strong>sum<\/strong> variable for each line in the input, and after processing all lines, the <code class=\"\" data-line=\"\">END { print $sum }<\/code> block prints the final sum to the terminal.<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27363\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.-Sum-up-a-column-of-floating-point-numbers-from-a-file-in-Bash.png\" alt=\"Sum up a column of floating point numbers from a file in Bash\" width=\"535\" height=\"242\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.-Sum-up-a-column-of-floating-point-numbers-from-a-file-in-Bash.png 535w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.-Sum-up-a-column-of-floating-point-numbers-from-a-file-in-Bash-300x136.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/>Here the program sums up the floating points <strong>4.5<\/strong>, <strong>10.1<\/strong>, and <strong>15.4<\/strong> and shows the result of summation <strong>30<\/strong> in the terminal.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In conclusion, there are numerous ways to sum up numbers in Bash. However, based on the context, users should choose the proper method to complete the task quickly and efficiently. I hope this article helps you understand and implement the various techniques available for summing numbers 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_find_the_sum_of_a_string_of_numbers_in_Bash\"><\/span>How to find the sum of a string of numbers in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Let\u2019s say you have numbers in a string in the following format-<\/p>\n<p><code class=\"\" data-line=\"\">numbers=&quot;10 20 30 40 50&quot;<\/code><\/p>\n<p>To find the sum of numbers of the above string use the code below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">echo $(echo $numbers | tr &#039; &#039; &#039;+&#039; | bc)<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_numbers_from_two_files_simultaneously\"><\/span>How to add numbers from two files simultaneously?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use <strong>awk<\/strong> to sum integers row-wise from multiple files. Let\u2019s consider two files as follows-<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#file0.txt\n5\n19\n51\n10<\/code><\/pre>\n<pre><code class=\"language-bash\" data-line=\"\">#file1.txt\n75\n11\n43\n845<\/code><\/pre>\n<pre><code class=\"language-bash\" data-line=\"\">paste file0.txt file1.txt | awk &#039;{ sum=0; for(i=1; i&lt;=NF; i++) sum+=$i; print sum }&#039;<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_to_increment_a_variable_by_one_in_Bash\"><\/span>How to increment a variable by one in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To increment a variable by one use the post or pre-increment syntax depending on the situation. For example, <strong>((var++))<\/strong> and <strong>((++var)) <\/strong>increase the value of the <strong>var <\/strong>variable by one.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\"># Declare a variable\nvar=5\n# Increment the variable by one\n((var++))\necho $var # output:6 <\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_to_perform_a_column-wise_sum_of_numbers_from_a_file\"><\/span>How to perform a column-wise sum of numbers from a file?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To perform a column-wise sum of numbers of a multi-columned file use the <strong>awk<\/strong> command. Let\u2019s say you have a file with numbers arranged as follows-<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#data.txt\n\n10 5\n4 9\n11 23<\/code><\/pre>\n<p>To add up numbers column-wise for the two columns of the <strong>data.txt <\/strong>file, use the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">awk &#039;{sum1+=$1; sum2+=$2} END {print &quot;Column 1 sum:&quot;, sum1, &quot;\\nColumn 2 sum:&quot;, sum2}&#039; &quot;data.txt&quot;<\/code><\/pre>\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\/divide\/\" target=\"_blank\" rel=\"noopener\">How to Divide Two Numbers in Bash [8 Easy Ways]<\/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;27354&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;2&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&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;5\\\/5 - (2 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Sum Up Numbers in Bash [Explained With Examples]&quot;,&quot;width&quot;:&quot;142.5&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: 142.5px;\">\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            5\/5 - (2 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Adding numbers is one of the basic math operations one needs to perform. In the Bash shell, there are a &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Sum Up Numbers in Bash [Explained With Examples]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#more-27354\" aria-label=\"Read more about How to Sum Up Numbers in Bash [Explained With Examples]\">Read more<\/a><\/p>\n","protected":false},"author":314903,"featured_media":27356,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[170],"class_list":["post-27354","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 Sum Up Numbers in Bash [Explained With Examples] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Addition is one of the basic math operations. This article shows how to sum numbers in Bash using various commands.\" \/>\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\/sum-numbers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Sum Up Numbers in Bash [Explained With Examples] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Addition is one of the basic math operations. This article shows how to sum numbers in Bash using various commands.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/\" \/>\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-16T11:15:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-04T14:19:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/bash-sum-numbers-.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=\"8 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\\\/sum-numbers\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/\"},\"author\":{\"name\":\"Md Zahidul Islam Laku\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\"},\"headline\":\"How to Sum Up Numbers in Bash [Explained With Examples]\",\"datePublished\":\"2023-11-16T11:15:07+00:00\",\"dateModified\":\"2024-05-04T14:19:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/\"},\"wordCount\":1509,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/bash-sum-numbers-.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\\\/sum-numbers\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/\",\"name\":\"How to Sum Up Numbers in Bash [Explained With Examples] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/bash-sum-numbers-.png\",\"datePublished\":\"2023-11-16T11:15:07+00:00\",\"dateModified\":\"2024-05-04T14:19:40+00:00\",\"description\":\"Addition is one of the basic math operations. This article shows how to sum numbers in Bash using various commands.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/bash-sum-numbers-.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/bash-sum-numbers-.png\",\"width\":400,\"height\":400,\"caption\":\"bash sum numbers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/operator\\\/arithmetic-operators\\\/sum-numbers\\\/#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 Sum Up Numbers in Bash [Explained With Examples]\"}]},{\"@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 Sum Up Numbers in Bash [Explained With Examples] - LinuxSimply","description":"Addition is one of the basic math operations. This article shows how to sum numbers in Bash using various commands.","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\/sum-numbers\/","og_locale":"en_US","og_type":"article","og_title":"How to Sum Up Numbers in Bash [Explained With Examples] - LinuxSimply","og_description":"Addition is one of the basic math operations. This article shows how to sum numbers in Bash using various commands.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/zahidlaku72","article_published_time":"2023-11-16T11:15:07+00:00","article_modified_time":"2024-05-04T14:19:40+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/bash-sum-numbers-.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":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/"},"author":{"name":"Md Zahidul Islam Laku","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21"},"headline":"How to Sum Up Numbers in Bash [Explained With Examples]","datePublished":"2023-11-16T11:15:07+00:00","dateModified":"2024-05-04T14:19:40+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/"},"wordCount":1509,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/bash-sum-numbers-.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\/sum-numbers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/","name":"How to Sum Up Numbers in Bash [Explained With Examples] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/bash-sum-numbers-.png","datePublished":"2023-11-16T11:15:07+00:00","dateModified":"2024-05-04T14:19:40+00:00","description":"Addition is one of the basic math operations. This article shows how to sum numbers in Bash using various commands.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/bash-sum-numbers-.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/bash-sum-numbers-.png","width":400,"height":400,"caption":"bash sum numbers"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/arithmetic-operators\/sum-numbers\/#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 Sum Up Numbers in Bash [Explained With Examples]"}]},{"@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\/27354","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=27354"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/27354\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/27356"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=27354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=27354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=27354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}