{"id":23126,"date":"2023-09-26T11:10:06","date_gmt":"2023-09-26T11:10:06","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=23126"},"modified":"2024-01-23T05:38:34","modified_gmt":"2024-01-23T05:38:34","slug":"bash-variable-addition","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/","title":{"rendered":"Addition of Bash Variables [4+ Examples]"},"content":{"rendered":"<p style=\"text-align: justify;\">Addition is one of the most basic arithmetic operations. In data processing, programmers need to add variables to make calculations and make subsequent decisions. In this article, I will explore different approaches to the addition of the <strong>Bash variable<\/strong>. It includes <strong>arithmetic expansion<\/strong>, <strong>expr command<\/strong>, <strong>bc command<\/strong>, and last but not least <strong>awk command<\/strong> approach.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/bash-variable-addition.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 Addition of Bash Variables<\/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\/variables\/usage\/variable-addition\/#Add_Two_Variables_in_the_Bash_Scripts\" >Add Two Variables in the Bash Scripts<\/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\/variables\/usage\/variable-addition\/#4_Practical_Examples_of_Variable_Addition_in_Bash_Scripts\" >4 Practical Examples of Variable Addition in Bash Scripts<\/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\/variables\/usage\/variable-addition\/#1_Using_Arithmetic_Expansion_for_Addition_of_Bash_Variables\" >1. Using Arithmetic Expansion for Addition of Bash Variables<\/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\/variables\/usage\/variable-addition\/#2_Calculate_Sum_With_Command_Line_Arguments\" >2. Calculate Sum With Command Line Arguments<\/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\/variables\/usage\/variable-addition\/#3_Calculate_Sum_With_Run_Time_Input\" >3. Calculate Sum With Run Time Input<\/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\/variables\/usage\/variable-addition\/#4_Using_Commands_for_Addition_of_Bash_Variables\" >4. Using Commands for Addition of Bash Variables<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#A_Adding_Two_Variables_With_the_%E2%80%9Cexpr%E2%80%9D_Command_in_Bash_Script\" >A. Adding Two Variables With the &#8220;expr&#8221; Command in Bash Script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#B_Adding_Floating-Point_Numbers_in_Bash_Using_%E2%80%9Cbc%E2%80%9D_Command\" >B. Adding Floating-Point Numbers in Bash Using &#8220;bc&#8221; Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#C_Adding_Floating-Point_Numbers_in_Bash_Using_%E2%80%9Cawk%E2%80%9D_Command\" >C. Adding Floating-Point Numbers in Bash Using &#8220;awk&#8221; Command<\/a><\/li><\/ul><\/li><\/ul><\/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\/variables\/usage\/variable-addition\/#Conclusion\" >Conclusion<\/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\/variables\/usage\/variable-addition\/#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-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#How_do_I_increase_the_variable_value_in_Bash\" >How do I increase the variable value in Bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#How_do_you_add_variables_together_in_Bash\" >How do you add variables together 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\/variables\/usage\/variable-addition\/#What_are_functions_called_in_Bash\" >What are functions called 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\/variables\/usage\/variable-addition\/#What_is_%E2%80%9Ci%E2%80%9D_in_Bash\" >What is &#8220;i++&#8221; in Bash?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Add_Two_Variables_in_the_Bash_Scripts\"><\/span>Add Two Variables in the Bash Scripts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To add two variables in bash, you can use several commands or approaches. Here are some methods to perform variable addition:<\/p>\n<ol>\n<li>Straightforward approach to add two variables in bash:\n<pre><code class=\"language-bash\" data-line=\"\">sum=$(($num1 + $num2))<\/code><\/pre>\n<\/li>\n<li>Using expr command with quotes:\n<pre><code class=\"language-bash\" data-line=\"\">sum=&#039;expr $num1 + $num2&#039;<\/code><\/pre>\n<\/li>\n<li>Use the expr command with dollar symbol:\n<pre><code class=\"language-bash\" data-line=\"\">sum=$(expr $num1 + $num2)<\/code><\/pre>\n<\/li>\n<li>Using bc command:\n<pre><code class=\"language-bash\" data-line=\"\">echo $num1 + $num2 | bc -l<\/code><\/pre>\n<\/li>\n<li>Using awk command:\n<pre><code class=\"language-bash\" data-line=\"\">echo 1.5 3.3 | awk &#039;{print $1 + $2}&#039;<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"4_Practical_Examples_of_Variable_Addition_in_Bash_Scripts\"><\/span>4 Practical Examples of Variable Addition in Bash Scripts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In this section, I have listed some examples of the process of <strong>addition of bash variables<\/strong> which will help you to grow your bash variable addition skill in Bash script. This includes examples of arithmetic expansion, bc command, awk command, expr command, and command line argument approach.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Using_Arithmetic_Expansion_for_Addition_of_Bash_Variables\"><\/span>1. Using Arithmetic Expansion for Addition of Bash Variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">An easy approach to addition is using <strong>arithmetic expansion<\/strong>. Here I will show you this straightforward approach where <strong>num1<\/strong> and <strong>num2<\/strong> are two variables added and saved to the sum variable. Then the <strong>sum variable<\/strong> is printed on the terminal.<\/p>\n<p>To perform addition in Bash using arithmetic expansion, you can utilize the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#setting value to num1 and num2\nnum1=10\nnum2=20\n\n#addition of num1 and num2 variable directly\nsum=$(($num1 + $num2))\n\n#printing value of sum variable\necho $sum<\/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><code class=\"\" data-line=\"\">#!\/bin\/bash<\/code><strong>,<\/strong>\u00a0is called <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/what-is-shebang\/\" target=\"_blank\" rel=\"noopener\"><strong>shebang or hashbang<\/strong><\/a>. It indicates the <strong>interpreter to be used <\/strong>for executing the script, in this case, it\u2019s bash. After that, the <code class=\"\" data-line=\"\">num1=10 num2=20<\/code> command has assigned value to <code class=\"\" data-line=\"\">num1 <\/code>and <code class=\"\" data-line=\"\">num2 <\/code>variables. Subsequently, the <code class=\"\" data-line=\"\">sum=$(($num1 + $num2))<\/code> command has calculated the <strong>addition<\/strong> of the <code class=\"\" data-line=\"\">num1 <\/code>and <code class=\"\" data-line=\"\">num2 <\/code>variables. Lastly, the <code class=\"\" data-line=\"\">echo $sum<\/code> command has printed the result on the terminal.<\/p>\n<\/div><\/div>\n<p style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-23133 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/1-bash-variable-addition-directly.png\" alt=\"The Bash script has added the bash variables num1 and num2 with arithmetic expansion and printed the result on the terminal.\" width=\"591\" height=\"175\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/1-bash-variable-addition-directly.png 591w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/1-bash-variable-addition-directly-300x89.png 300w\" sizes=\"(max-width: 591px) 100vw, 591px\" \/>The image shows that the Bash script has added the <strong>variables num1 and num2<\/strong> with <strong>arithmetic expansion<\/strong> and printed the result on the terminal.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Calculate_Sum_With_Command_Line_Arguments\"><\/span>2. Calculate Sum With Command Line Arguments<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Command-line arguments in Bash are values provided to a script or command when it is executed in the terminal. These arguments allow you to pass information to the script or command during runtime.<\/p>\n<p>To calculate the sum of command-line arguments in Bash, you can use the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Calculate the sum via command-line arguments\n# $1 and $2 refers to the first and second argument passed as command-line arguments\n# Calculating the summation of these two arguments\nsum=$(( $1 + $2 ))\n\n#printing the summation result\necho &quot;Sum 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>The <code class=\"\" data-line=\"\">sum=$(( $1 + $2 ))<\/code> command has added the two arguments passed to the Bash script.\u00a0 These <code class=\"\" data-line=\"\">$1<\/code> and <code class=\"\" data-line=\"\">$2<\/code> are <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/positional-parameters\/#What_is_a_Positional_Parameter\" target=\"_blank\" rel=\"noopener\"><strong>positional parameters<\/strong><\/a>. After that, the <code class=\"\" data-line=\"\">echo &quot;Sum is: $sum&quot;<\/code> command has printed the sum on the terminal.<\/p>\n<\/div><\/div>\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> Here 5 and 7 are input arguments. <\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-23134 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/2-command-line-argument.png\" alt=\"The addition of two bash variables is calculated with the help of the command line argument.\" width=\"600\" height=\"175\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/2-command-line-argument.png 600w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/2-command-line-argument-300x88.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/>The image shows that the summation of two variables is calculated with the help of the command line argument.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Calculate_Sum_With_Run_Time_Input\"><\/span>3. Calculate Sum With Run Time Input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In this example, I will show you a bash script where the <strong>sum<\/strong> will be calculated with <strong>run time input<\/strong>. The <strong>num1 <\/strong>and <strong>num2<\/strong> are two numbers run time input and these two variables will be added then printed on the terminal.<\/p>\n<p>To calculate the sum of numbers provided at runtime as user input, you can use the following Bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#take input from user and calculate sum.\nread -p &quot;Enter First Number: &quot; num1\nread -p &quot;Enter Second Number: &quot; num2\n\n#adding variable num1 and num2\nsum=$(( $num1 + $num2 ))\n\n#printing value of sum\necho &quot;Sum 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>The <code class=\"\" data-line=\"\">read -p &quot;Enter First Number: &quot; num1<\/code><strong>; <\/strong><code class=\"\" data-line=\"\">read -p &quot;Enter Second Number: &quot; num2<\/code> commands have taken num1 and num2 run time input. Later on, the <code class=\"\" data-line=\"\">sum=$(( $num1 + $num2 ))<\/code> command calculated the summation of the <code class=\"\" data-line=\"\">num1 <\/code>and <code class=\"\" data-line=\"\">num2 <\/code>variables and saved it to the sum variable. Finally, the <code class=\"\" data-line=\"\">echo &quot;Sum is: $sum&quot;<\/code> command has printed the result on the terminal.<\/p>\n<\/div><\/div>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter wp-image-23135 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/3-Calculate-Sum-with-Run-Time-Input.png\" alt=\"The bash script has taken two run-time inputs, added them, and eventually printed the result on the terminal.\" width=\"607\" height=\"240\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/3-Calculate-Sum-with-Run-Time-Input.png 607w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/3-Calculate-Sum-with-Run-Time-Input-300x119.png 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/>The image shows that the bash script has taken <strong>two run-time inputs<\/strong>, <strong>added them<\/strong>, and eventually printed the result on the terminal.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Using_Commands_for_Addition_of_Bash_Variables\"><\/span>4. Using Commands for Addition of Bash Variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">There are some approaches to adding bash variables using <a href=\"https:\/\/linuxsimply.com\/commands\/\" target=\"_blank\" rel=\"noopener\"><strong>commands<\/strong><\/a>. Three approaches including the <strong>expr command<\/strong>, the <strong>awk command<\/strong>, and the <strong>bc command<\/strong> are given below<\/p>\n<h4><span class=\"ez-toc-section\" id=\"A_Adding_Two_Variables_With_the_%E2%80%9Cexpr%E2%80%9D_Command_in_Bash_Script\"><\/span>A. Adding Two Variables With the &#8220;expr&#8221; Command in Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">There are two approaches to using the expr command to add two variables with the <strong>expr command<\/strong>. The first approach is with single quotes and the syntax is:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">sum=&#039;expr $num1 + $num2&#039;<\/code><\/pre>\n<p>And the second approach is without quotes and the syntax is:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">sum=$(expr $num1 + $num2)<\/code><\/pre>\n<p style=\"text-align: justify;\">Here I have developed a code to <strong>add num1 <\/strong>and<strong> num2 variables<\/strong> incorporating the second approach.<\/p>\n<p style=\"text-align: justify;\">To add two variables without using the quoting syntax, follow the script below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#setting value to num1 and num2\nnum1=40\nnum2=30\n\n#addition of num1 and num2 variable with expr command\nsum=$(expr $num1 + $num2)\n\n#printing value of sum variable\necho $sum<\/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 <code class=\"\" data-line=\"\">num1=40 num2=30 <\/code>command has assigned value to <code class=\"\" data-line=\"\">num1 <\/code>and <code class=\"\" data-line=\"\">num2 <\/code>variables. Subsequently, the <code class=\"\" data-line=\"\">sum=$(expr $num1 + $num2)<\/code> command has calculated the summation of these two variables. Finally, the <a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\"><strong>echo command<\/strong><\/a> has printed the result on the terminal.<\/p>\n<\/div><\/div>\n<p style=\"text-align: justify;\" data-wp-editing=\"1\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-23136 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/4-bash-variable-addition-with-expr-command.png\" alt=\"The expr command has done the addition of two bash variables then the echo command has printed it on the terminal.\" width=\"593\" height=\"173\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/4-bash-variable-addition-with-expr-command.png 593w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/4-bash-variable-addition-with-expr-command-300x88.png 300w\" sizes=\"(max-width: 593px) 100vw, 593px\" \/>The image shows that the <strong>expr command<\/strong> has added two numbers then the <strong>echo command<\/strong> has printed it on the terminal.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"B_Adding_Floating-Point_Numbers_in_Bash_Using_%E2%80%9Cbc%E2%80%9D_Command\"><\/span>B. Adding Floating-Point Numbers in Bash Using &#8220;bc&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">The <a href=\"https:\/\/linuxsimply.com\/bc-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>bc command<\/strong><\/a> means <strong>b<\/strong>asic <strong>c<\/strong>alculator. In this example, I will set two variables first, then add these two variables incorporating the <strong>pipe command<\/strong> and <strong>bc command<\/strong>. Follow the below script to know more.<\/p>\n<p>To add floating-point numbers in bash using <strong>bc<\/strong> <strong>command<\/strong>, use the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#setting num1 and num2 variable\nnum1=3.1416\nnum2=1.5\n\n#adding num1 and num2 with bc command associated with pipe command then print it\necho $num1 + $num2 | bc -l<\/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 <code class=\"\" data-line=\"\">num1=3.1416 num2=1.5<\/code> command has assigned value to num1 and <code class=\"\" data-line=\"\">num2 <\/code>variables. Then the <code class=\"\" data-line=\"\">echo $num1 + $num2 | bc -l<\/code> command has <strong>passed the output<\/strong> of <code class=\"\" data-line=\"\">$num1 + $num2<\/code> command to the <strong>bc command<\/strong> and the bc command has calculated the summation of these two numbers. Finally, the <strong>echo command<\/strong> has printed the result on the terminal.<\/p>\n<\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-23137 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/5-float-bc.png\" alt=\"The bc command has added the float numbers 3.1416 and 1.5 and the echo command has printed the result on the terminal.\" width=\"601\" height=\"176\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/5-float-bc.png 601w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/5-float-bc-300x88.png 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/>The image shows that the <strong>bc command has added<\/strong> the float numbers 3.1416 and 1.5 and the <strong>echo command<\/strong> has printed the result on the terminal.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"C_Adding_Floating-Point_Numbers_in_Bash_Using_%E2%80%9Cawk%E2%80%9D_Command\"><\/span>C. Adding Floating-Point Numbers in Bash Using &#8220;awk&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">The <a href=\"https:\/\/linuxsimply.com\/awk-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>awk command<\/strong><\/a> command is helpful to do the mathematical addition without further compilation. In this example, I will pass two variables to the <strong>awk command<\/strong> incorporating the <strong>pipe command<\/strong>.<\/p>\n<p style=\"text-align: justify;\">If you prefer to use awk for adding floating-point numbers in Bash, you can follow this example script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#two arguments are added utilizing the awk command and then printed on the terminal utilizing echo command\necho 1.5 3.3 | awk &#039;{print $1 + $2}&#039;<\/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 <code class=\"\" data-line=\"\">echo 1.5 3.3 | awk &#039;{print $1 + $2}&#039; <\/code>command has passed 1.5 and 3.3 as <code class=\"\" data-line=\"\">$1<\/code> and <code class=\"\" data-line=\"\">$2<\/code> to the <strong>awk command<\/strong> which has <strong>added<\/strong> these two numbers by <strong>+<\/strong> <strong>sign<\/strong>. And finally, the <strong>echo command<\/strong> has printed the result.<\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-23138 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/6-float-awk.png\" alt=\"The awk command has added 1.5 and 3.3 and the echo command has printed the result on the terminal.\" width=\"599\" height=\"183\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/6-float-awk.png 599w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/6-float-awk-300x92.png 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/>The image shows that the <strong>awk command<\/strong> has added 1.5 and 3.3 and the <strong>echo command<\/strong> has printed the result on 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;\">Here I have demonstrated some approaches to <strong>adding bash variables<\/strong>. I hope, after going through this article, you will be productive enough to do bash variable addition whenever necessary.<\/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_do_I_increase_the_variable_value_in_Bash\"><\/span>How do I increase the variable value in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can increase variable value Using Increment (++) Operators in Bash. When using the <strong>++ operator<\/strong> as a <strong>prefix like ++var<\/strong>. Then first the value of the variable is incremented by 1, and it returns the value. When using the ++ operator as a <strong>postfix like var++<\/strong>. Then first original value will returned and after that, the value incremented by 1.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_you_add_variables_together_in_Bash\"><\/span>How do you add variables together in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To add variables together in Bash, you can use the ((&#8230;)) syntax for arithmetic expansion. Here&#8217;s an example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Assuming num1 and num2 are variables with numeric values\nnum1=10\nnum2=5\n\n# Add the values of num1 and num2 and store the result in a variable\nresult=$((num1 + num2))\n\n# Print the result\necho &quot;The sum of $num1 and $num2 is: $result&quot;\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"What_are_functions_called_in_Bash\"><\/span>What are functions called in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A bash function is a method, programmers commonly use in shell scripts to group <strong>reusable code blocks<\/strong>. This feature is available for most programming languages, known under different names such as procedures, methods, or subroutines.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_%E2%80%9Ci%E2%80%9D_in_Bash\"><\/span>What is &#8220;i++&#8221; in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In Bash, <strong>++<\/strong> is not used as an increment operator like it is in some other programming languages. Bash doesn&#8217;t have a direct increment operator like <strong>++<\/strong> or <strong>&#8212;<\/strong>. However, you can increment a variable using other constructs.<\/p>\n<p>Here&#8217;s an example using the let command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Assuming i is a variable with a numeric value\ni=5\n\n# Increment i by 1\nlet &quot;i++&quot;\n\n# Print the result\necho &quot;The value of i after incrementing: $i&quot;\n<\/code><\/pre>\n<p>In this example, <code class=\"\" data-line=\"\">let &quot;i++&quot;<\/code> increments the value of the variable i by 1. After this operation, the script prints the updated value of i. You can use similar constructs with other arithmetic operations to achieve the desired increment behaviour in Bash.<br \/>\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"How do I increase the variable value in Bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"You can increase variable value Using Increment (++) Operators in Bash. When using the ++ operator as a prefix like ++var. Then first the value of the variable is incremented by 1, and it returns the value. When using the ++ operator as a postfix like var++. Then first original value will returned and after that, the value incremented by 1.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How do you add variables together in Bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To add variables together in Bash, you can use the ((...)) syntax for arithmetic expansion. Here's an example:<\/p>\n<p>#!\/bin\/bash<\/p>\n<p># Assuming num1 and num2 are variables with numeric values\nnum1=10\nnum2=5<\/p>\n<p># Add the values of num1 and num2 and store the result in a variable\nresult=$((num1 + num2))<\/p>\n<p># Print the result\necho \\\"The sum of $num1 and $num2 is: $result\\\"\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What are functions called in Bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"A bash function is a method, programmers commonly use in shell scripts to group reusable code blocks. This feature is available for most programming languages, known under different names such as procedures, methods, or subroutines.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is 'i++' in Bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"In Bash, ++ is not used as an increment operator like it is in some other programming languages. Bash doesn't have a direct increment operator like ++ or --. However, you can increment a variable using other constructs.<\/p>\n<p>Here's an example using the let command:<\/p>\n<p>#!\/bin\/bash<\/p>\n<p># Assuming i is a variable with a numeric value\ni=5<\/p>\n<p># Increment i by 1\nlet \\\"i++\\\"<\/p>\n<p># Print the result\necho \\\"The value of i after incrementing: $i\\\"<\/p>\n<p>In this example, let \\\"i++\\\" increments the value of the variable i by 1. After this operation, the script prints the updated value of i. You can use similar constructs with other arithmetic operations to achieve the desired increment behaviour in Bash.\"\n    }\n  }]\n}\n<\/script><\/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\/variables\/usage\/echo-variable\/\" target=\"_blank\" rel=\"noopener\">How to Echo Variables in Bash Script? [4 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/use-variable-in-string\/\" target=\"_blank\" rel=\"noopener\">How to Use String Variables in Bash Script? [4 Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/append-string-to-variable\/\" target=\"_blank\" rel=\"noopener\">How to Append String to Bash Variable? [2 Effective Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/check-if-variable-exists\/\" target=\"_blank\" rel=\"noopener\">How to Check If Bash Variable Exists? [2 Effective Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/check-if-variable-is-empty\/\" target=\"_blank\" rel=\"noopener\">How To Check if Bash Variable is Empty? [2 Easy Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/set-and-list-environment-variables\/\" target=\"_blank\" rel=\"noopener\">How to List and Set Bash Environment Variables? [3 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/unset-env-variable\/\" target=\"_blank\" rel=\"noopener\">2 Ways to Unset Environment Variables Using Bash Script<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/check-if-environment-variable-is-set\/\" target=\"_blank\" rel=\"noopener\">5 Methods to Check If Environment Variable is Set in Bash Script<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/path-variable\/\" target=\"_blank\" rel=\"noopener\">How to Set Bash $PATH Variable? [Easiest Configuration]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/execute-command-in-variable\/\" target=\"_blank\" rel=\"noopener\">2 Cases to Execute Command Stored in Bash Variable<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/command-output-to-variable\/\" target=\"_blank\" rel=\"noopener\">How to Store Command Output to Bash Variable? [3 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/read-file-into-variable\/\" target=\"_blank\" rel=\"noopener\">How to Read a File into Bash Variable? [2 Simple Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/write-variable-to-file\/\" target=\"_blank\" rel=\"noopener\">How to Write Bash Variable to File? [3 Effective Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/compare-variables\/\" target=\"_blank\" rel=\"noopener\">Compare Variables in Bash Scripts [3 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/increment-variable\/\" target=\"_blank\" rel=\"noopener\">Increment Variable Value in Bash Scripts [4+ Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/add-1-to-variable\/\" target=\"_blank\" rel=\"noopener\">Adding 1 to Bash Variable [3 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/decrement-variable\/\" target=\"_blank\" rel=\"noopener\">Decrement Variable Value in Bash Scripts [4+ Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/subtract-two-variables\/\" target=\"_blank\" rel=\"noopener\">How to Subtract Two Bash Variables? [4+ Easy Approaches]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/multiply-variable\/\" target=\"_blank\" rel=\"noopener\">How to Multiply Variable in Bash [6+ Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-substitution\/\" target=\"_blank\" rel=\"noopener\">Variable Substitution in Bash [Replace Character &amp; Substring]<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Using Variables in Bash Scripting&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\/variables\/usage\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/\" target=\"_blank\" rel=\"noopener\">Using Variables in Bash Scripting<\/a><\/span> | <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Variables&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\/variables\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/\" target=\"_blank\" rel=\"noopener\">Bash Variables<\/a><\/span> | <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Scripting Tutorial&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\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/span><\/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;23126&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;Addition of Bash Variables [4+ Examples]&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>Addition is one of the most basic arithmetic operations. In data processing, programmers need to add variables to make calculations &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Addition of Bash Variables [4+ Examples]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#more-23126\" aria-label=\"Read more about Addition of Bash Variables [4+ Examples]\">Read more<\/a><\/p>\n","protected":false},"author":314894,"featured_media":23139,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[121],"class_list":["post-23126","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-using-variables-in-bash","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>Addition of Bash Variables [4+ Examples] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Addition of Bash variable is one of the basic operations for data manupulation and here i have explore this process in different approaches.\" \/>\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\/variables\/usage\/variable-addition\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Addition of Bash Variables [4+ Examples] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Addition of Bash variable is one of the basic operations for data manupulation and here i have explore this process in different approaches.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/dasgupta.susmit\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-26T11:10:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-23T05:38:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/bash-variable-addition-feature-image.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=\"Susmit Das Gupta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Susmit Das Gupta\" \/>\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\\\/variables\\\/usage\\\/variable-addition\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/\"},\"author\":{\"name\":\"Susmit Das Gupta\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/38abbef9a1053d9faec8935dc39f10fa\"},\"headline\":\"Addition of Bash Variables [4+ Examples]\",\"datePublished\":\"2023-09-26T11:10:06+00:00\",\"dateModified\":\"2024-01-23T05:38:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/\"},\"wordCount\":1512,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/bash-variable-addition-feature-image.png\",\"keywords\":[\"using variables in bash\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/\",\"name\":\"Addition of Bash Variables [4+ Examples] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/bash-variable-addition-feature-image.png\",\"datePublished\":\"2023-09-26T11:10:06+00:00\",\"dateModified\":\"2024-01-23T05:38:34+00:00\",\"description\":\"Addition of Bash variable is one of the basic operations for data manupulation and here i have explore this process in different approaches.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/bash-variable-addition-feature-image.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/bash-variable-addition-feature-image.png\",\"width\":400,\"height\":400,\"caption\":\"bash variable addition\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/variable-addition\\\/#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 Variables\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Using Variables in Bash Scripting\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/usage\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Addition of Bash Variables [4+ 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\\\/38abbef9a1053d9faec8935dc39f10fa\",\"name\":\"Susmit Das Gupta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Susmit-Das-Gupta-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Susmit-Das-Gupta-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Susmit-Das-Gupta-II-96x96.png\",\"caption\":\"Susmit Das Gupta\"},\"description\":\"Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/dasgupta.susmit\",\"https:\\\/\\\/www.instagram.com\\\/susmit_dasgupta\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/susmitdasgupta\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/susmit\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Addition of Bash Variables [4+ Examples] - LinuxSimply","description":"Addition of Bash variable is one of the basic operations for data manupulation and here i have explore this process in different approaches.","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\/variables\/usage\/variable-addition\/","og_locale":"en_US","og_type":"article","og_title":"Addition of Bash Variables [4+ Examples] - LinuxSimply","og_description":"Addition of Bash variable is one of the basic operations for data manupulation and here i have explore this process in different approaches.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/dasgupta.susmit","article_published_time":"2023-09-26T11:10:06+00:00","article_modified_time":"2024-01-23T05:38:34+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/bash-variable-addition-feature-image.png","type":"image\/png"}],"author":"Susmit Das Gupta","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Susmit Das Gupta","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/"},"author":{"name":"Susmit Das Gupta","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/38abbef9a1053d9faec8935dc39f10fa"},"headline":"Addition of Bash Variables [4+ Examples]","datePublished":"2023-09-26T11:10:06+00:00","dateModified":"2024-01-23T05:38:34+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/"},"wordCount":1512,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/bash-variable-addition-feature-image.png","keywords":["using variables in bash"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/","name":"Addition of Bash Variables [4+ Examples] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/bash-variable-addition-feature-image.png","datePublished":"2023-09-26T11:10:06+00:00","dateModified":"2024-01-23T05:38:34+00:00","description":"Addition of Bash variable is one of the basic operations for data manupulation and here i have explore this process in different approaches.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/bash-variable-addition-feature-image.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/bash-variable-addition-feature-image.png","width":400,"height":400,"caption":"bash variable addition"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/variable-addition\/#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 Variables","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/"},{"@type":"ListItem","position":4,"name":"Using Variables in Bash Scripting","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/usage\/"},{"@type":"ListItem","position":5,"name":"Addition of Bash Variables [4+ 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\/38abbef9a1053d9faec8935dc39f10fa","name":"Susmit Das Gupta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Susmit-Das-Gupta-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Susmit-Das-Gupta-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Susmit-Das-Gupta-II-96x96.png","caption":"Susmit Das Gupta"},"description":"Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/dasgupta.susmit","https:\/\/www.instagram.com\/susmit_dasgupta\/","https:\/\/www.linkedin.com\/in\/susmitdasgupta\/"],"url":"https:\/\/linuxsimply.com\/author\/susmit\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/23126","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\/314894"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=23126"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/23126\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/23139"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=23126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=23126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=23126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}