{"id":26071,"date":"2023-11-06T04:24:53","date_gmt":"2023-11-06T04:24:53","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=26071"},"modified":"2023-12-04T03:18:29","modified_gmt":"2023-12-04T03:18:29","slug":"bash-compare-numbers","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/","title":{"rendered":"How to Compare Numbers in Bash With If Statement [2 Methods]"},"content":{"rendered":"<p style=\"text-align: justify;\">Compare Numbers in <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/\" target=\"_blank\" rel=\"noopener\">Bash scripting<\/a><\/u><\/strong>\u00a0is essential for a wide range of tasks, including arithmetic calculations and logical decisions. Therefore, it is fundamental for any developer to understand how the bash can compare numbers in order to facilitate these operations.<\/p>\n<p style=\"text-align: justify;\">In this article, I will provide you with <strong>2<\/strong> reliable methods to compare numbers in Bash, ensuring seamless scripting for your specific needs. Explore now for expert insights.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Practice_files_bash-if-compare-numbers-1.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 to Compare 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\/conditional-statements\/if-else\/compare-numbers\/#Basics_of_Number_Comparison\" >Basics of Number Comparison<\/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\/conditional-statements\/if-else\/compare-numbers\/#1_Compare_Numbers_in_Bash_Using_Square_Brackets\" >1. Compare Numbers in Bash Using Square Brackets<\/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\/conditional-statements\/if-else\/compare-numbers\/#Using_%E2%80%9C-gt%E2%80%9D_Option\" >Using \u201c-gt\u201d Option<\/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\/conditional-statements\/if-else\/compare-numbers\/#Using_%E2%80%9C-lt%E2%80%9D_Option\" >Using \u201c-lt\u201d Option<\/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\/conditional-statements\/if-else\/compare-numbers\/#Using%E2%80%9C-eq%E2%80%9D_Option\" >Using\u201c-eq\u201d Option<\/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\/conditional-statements\/if-else\/compare-numbers\/#Using_%E2%80%9C-ne%E2%80%9D_Option\" >Using \u201c-ne\u201d Option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Utilizing_%E2%80%9C-ge%E2%80%9D_Option\" >Utilizing \u201c-ge\u201d Option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Using_%E2%80%9C-le%E2%80%9D_Option\" >Using \u201c-le\u201d Option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Summary_of_Operators_to_Compare_Numbers_in_Bash\" >Summary of Operators to Compare Numbers in Bash<\/a><\/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\/conditional-statements\/if-else\/compare-numbers\/#2_Compare_Numbers_in_Bash_Using_Double_Parenthesis\" >2. Compare Numbers in Bash Using Double Parenthesis<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Using_Greater_Than_Sign_%E2%80%9C%3E%E2%80%9D\" >Using Greater Than Sign \u201c&gt;\u201d<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Using_the_Less_Than_Sign_%E2%80%9C\" >Using the Less Than Sign \u201c&lt;\u201d<\/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\/conditional-statements\/if-else\/compare-numbers\/#Using_Equal_to_Operator_%E2%80%9C%E2%80%9D\" >Using Equal to Operator \u201c==\u201d<\/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\/conditional-statements\/if-else\/compare-numbers\/#Using_Not_Equal_To_Sign_%E2%80%9C%E2%80%9D\" >Using Not Equal To Sign \u201c!=\u201d<\/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\/conditional-statements\/if-else\/compare-numbers\/#Using_Greater_Or_Equal_To_Sign_%E2%80%9C%3E%E2%80%9D\" >Using Greater Or Equal To Sign \u201c&gt;=\u201d<\/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\/conditional-statements\/if-else\/compare-numbers\/#Using_Less_Or_Equal_to_Sign_%E2%80%9C\" >Using Less Or Equal to Sign \u201c&lt;=\u201d<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Summary_of_Operators_for_Double_Parenthesis\" >Summary of Operators for Double Parenthesis<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-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-20\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#How_to_compare_strings_in_bash\" >How to compare strings in bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Can_I_use_%E2%80%98regex_operator_to_compare_numbers_in_bash\" >Can I use \u2018regex\u2019 operator to compare numbers in bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#How_can_I_compare_two_floating_point_numbers_in_bash\" >How can I compare two floating point numbers in bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#Can_I_compare_three_numbers_in_Linux\" >Can I compare three numbers in Linux?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Basics_of_Number_Comparison\"><\/span>Basics of Number Comparison<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">A number comparison is a way of comparing numbers to figure out the relationship between them. For example, you can compare numbers to find out if they are equal, not equal, greater than, or less than. In order to achieve these objectives, bash provides two types of brackets: <strong>square brackets<\/strong> and <strong>double parenthesis<\/strong>.<\/p>\n<p style=\"text-align: justify;\">In addition, to compare numbers in bash, there are numerous comparison operators like <strong>greater than or equal (&gt;=), less than (&lt;), greater than (-gt), not equal to (!=), equal to (-eq)<\/strong>, and more that should be used inside the square brackets or parenthesis of the if statement. The if statement will execute a set of statements if the condition is true or false.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"1_Compare_Numbers_in_Bash_Using_Square_Brackets\"><\/span>1. Compare Numbers in Bash Using Square Brackets<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In Bash scripting, square brackets are used in conjunction with the <code class=\"\" data-line=\"\">if-else<\/code> statement to evaluate various conditions. You can use both single \u201c[\u201c and double square brackets \u201c[[\u201c, but if you want to be more advanced, double square brackets \u201c[[\u201c are the way to go.<\/p>\n<p style=\"text-align: justify;\">To compare numbers in bash, there are <strong>6<\/strong> different comparison operators: <code class=\"\" data-line=\"\">-gt<\/code>, <code class=\"\" data-line=\"\">-lt<\/code>, <code class=\"\" data-line=\"\">-eq<\/code>, <code class=\"\" data-line=\"\">-ne<\/code>, <code class=\"\" data-line=\"\">-ge<\/code>, and<code class=\"\" data-line=\"\"> -le<\/code>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_%E2%80%9C-gt%E2%80%9D_Option\"><\/span>Using \u201c-gt\u201d Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">-gt<\/code> option tests if a number is <strong>greater than<\/strong> another. The expression <code class=\"\" data-line=\"\">if [[ $number1 -gt $number2 ]]<\/code> checks if number1 is greater than number2 and evaluates to either <strong>true<\/strong> or <strong>false<\/strong> depending on the input.<\/p>\n<p style=\"text-align: justify;\">So, to compare numbers in Bash, you can use the <code class=\"\" data-line=\"\">-gt<\/code> option inside the double square brackets. Here\u2019s how it works:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif [[ $number1 -gt $number2 ]];\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is greater than number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not greater than number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\"><strong>If the number1 is greater than the number2, it will execute the<\/strong> <strong>if block<\/strong> code &#8220;Number1 is greater than number2&#8221; otherwise it will execute the <strong>else block<\/strong> code &#8220;Number1 is not greater than number2&#8221;.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-26074\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.output-of-gt.sh_.png\" alt=\"using -gt option to compare numbers in bash\" width=\"570\" height=\"387\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.output-of-gt.sh_.png 570w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/1.output-of-gt.sh_-300x204.png 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/p>\n<p style=\"text-align: justify;\">In this image, you can see that while giving input <strong>number1=10<\/strong> and input<strong> number2=8<\/strong>, it shows that &#8220;Number1 is greater than number2&#8221; as it\u2019s true. When you give <strong>number1=2<\/strong> and input <strong>number2=5<\/strong>, it shows that &#8220;Number1 is not greater than number2&#8221; as 2 is less than 5.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_%E2%80%9C-lt%E2%80%9D_Option\"><\/span>Using \u201c-lt\u201d Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><code class=\"\" data-line=\"\">-lt<\/code> is a less-than operator that compares numbers in bash by checking if the number1 is <strong>less than<\/strong> the number2.<\/p>\n<p style=\"text-align: justify;\">To compare numbers with the <code class=\"\" data-line=\"\">-lt<\/code> option, use this syntax <code class=\"\" data-line=\"\">if [ $number1 -lt $number2 ]<\/code>. See the script below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif [ $number1 -lt $number2 ];\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is less than number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not less than number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\"><strong>If the input number1 is less than the input number2. It returns<\/strong> <strong>true <\/strong>and prints &#8220;Number1 is less than number2&#8221;. On the other hand, it prints &#8220;Number1 is not less than number2&#8221;.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-26075\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.output-of-lt.sh_.png\" alt=\"using -lt option to compare numbers in bash\" width=\"519\" height=\"387\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.output-of-lt.sh_.png 519w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/2.output-of-lt.sh_-300x224.png 300w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/p>\n<p style=\"text-align: justify;\">The output says that if you take the number1= 5 and number2= 3, it&#8217;ll say that <strong>number1 is not less than number2<\/strong> because 5 is greater than 2. But if you take number1= 3 and number2= 6, it just says that<strong> number1 is less than number2<\/strong> since it&#8217;s correct.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using%E2%80%9C-eq%E2%80%9D_Option\"><\/span>Using\u201c-eq\u201d Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code class=\"\" data-line=\"\">-eq<\/code> option checks if two numbers are equal in their values. The script shows the use of it:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif [[ $number1 -eq $number2 ]];\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is equal to number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not equal to number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">If both input numbers are <strong>equal<\/strong>, it returns a <strong>true<\/strong> expression block &#8220;Number1 is equal to number2&#8221; otherwise, it returns a <strong>false<\/strong> expression block.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-26076\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.output-of-eq.sh_.png\" alt=\"using -eq option to compare numbers in bash\" width=\"506\" height=\"386\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.output-of-eq.sh_.png 506w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/3.output-of-eq.sh_-300x229.png 300w\" sizes=\"(max-width: 506px) 100vw, 506px\" \/><\/p>\n<p style=\"text-align: justify;\">You can observe that if both numbers are equal to<strong> 5<\/strong>, then executes <strong>Number1 is equal to Number2<\/strong>. Conversely, if different numbers such as <strong>4<\/strong> and <strong>5<\/strong> are inputted, it indicates that Number1 is different from Number2.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_%E2%80%9C-ne%E2%80%9D_Option\"><\/span>Using \u201c-ne\u201d Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Unlike <code class=\"\" data-line=\"\">-eq<\/code>, the <code class=\"\" data-line=\"\">-ne<\/code> checks whether the number1 is <strong>not equal<\/strong> to the number2. The below script shows how to use <code class=\"\" data-line=\"\">-ne<\/code> within <code class=\"\" data-line=\"\">if<\/code> statement to compare the inequality of two numbers:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif [ $number1 -ne $number2 ];\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not equal to number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is equal to number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">If the input numbers are not equal, it will execute the <strong>if code <\/strong>block &#8220;Number1 is not equal to number2&#8221;. Contrarily, it will execute the <strong>else code<\/strong> block.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26077\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.output-of-ne.sh_.png\" alt=\"using -ne option to compare numbers in bash\" width=\"505\" height=\"388\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.output-of-ne.sh_.png 505w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/4.output-of-ne.sh_-300x230.png 300w\" sizes=\"(max-width: 505px) 100vw, 505px\" \/><\/p>\n<p style=\"text-align: justify;\">When you take both of the inputs as <strong>4<\/strong>, you can see that Number1 is the same as Number2. But if you take <strong>3 <\/strong>and<strong> 4<\/strong>, it shows that <strong>Number1 is not equal to Number2<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Utilizing_%E2%80%9C-ge%E2%80%9D_Option\"><\/span>Utilizing \u201c-ge\u201d Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The expression <code class=\"\" data-line=\"\">-ge<\/code> prints the <strong>true<\/strong> output if a number is <strong>equal to<\/strong> or <strong>greater than<\/strong> another number. This is a bash script that uses the <code class=\"\" data-line=\"\">[[ $number1 -ge $number2 ]]<\/code>\u00a0 condition to compare numbers with the <code class=\"\" data-line=\"\">-ge<\/code> option:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif [[ $number1 -ge $number2 ]];\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is greater than and equal to number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not greater than and equal to number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">The if condition evaluates to <strong>true<\/strong> if number1 is <strong>greater than<\/strong> or <strong>equal to<\/strong> number2. If it returns false, it executes &#8220;Number1 is not greater than and equal to number2&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26078\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.output-of-ge.sh_.png\" alt=\"using -ge option to compare numbers in bash\" width=\"700\" height=\"351\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.output-of-ge.sh_.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/5.output-of-ge.sh_-300x150.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p style=\"text-align: justify;\">It displays &#8220;Number1 is greater than and equal to number2&#8221; after giving both input numbers as <strong>10<\/strong>. It shows different outputs when you give different input numbers.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_%E2%80%9C-le%E2%80%9D_Option\"><\/span>Using \u201c-le\u201d Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">-le<\/code> option works in the same way as <code class=\"\" data-line=\"\">-ge<\/code>, except that it checks whether the number is <strong>less than or equal<\/strong> to another number. Here\u2019s how to use it in a script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif [[ $number1 -le $number2 ]];\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is less than and equal to number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not less than and equal to number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">Here when number1 is less than or equal to number2, it will execute the <strong>if block<\/strong> expression. On the other hand, it will execute the <strong>else block<\/strong> expression.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26079\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.output-of-le.sh_.png\" alt=\"using -le option to compare numbers in bash\" width=\"700\" height=\"372\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.output-of-le.sh_.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/6.output-of-le.sh_-300x159.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p style=\"text-align: justify;\">When input number1 and number2 are <strong>20<\/strong>, it displays &#8220;Number1 is less than and equal to number2&#8221;. If the number1 is <strong>greater than<\/strong> or <strong>not equal<\/strong> to number2, it shows the &#8220;Number1 is not less than and equal to number2&#8221;.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Summary_of_Operators_to_Compare_Numbers_in_Bash\"><\/span>Summary of Operators to Compare Numbers in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The following <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/comparison-operators\/\" target=\"_blank\" rel=\"noopener\"><strong>comparison operators<\/strong><\/a> are used within square brackets to compare integer numbers in Bash.<\/p>\n<div class=\"su-table su-table-responsive su-table-alternate su-table-fixed\">\n<table style=\"width: 81.7896%;height: 532px\" width=\"0\">\n<tbody>\n<tr>\n<th style=\"width: 30.3922%\" width=\"184\"><strong>Comparison Operator<\/strong><\/th>\n<th style=\"width: 35.5392%\" width=\"216\"><strong>Syntax<\/strong><\/th>\n<th style=\"width: 32.9657%\" width=\"200\"><strong>Description<\/strong><\/th>\n<\/tr>\n<tr>\n<td style=\"text-align: center;width: 30.3922%\" width=\"184\"><strong>Greater than (-gt) <\/strong><\/td>\n<td style=\"text-align: center;width: 35.5392%\" width=\"216\">[[ $number1 -gt $number2 ]] or<br \/>\n[ $number1 -gt $number2 ]<\/td>\n<td style=\"text-align: center;width: 32.9657%\" width=\"200\">Returns true if the number1 is greater than number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;width: 30.3922%\" width=\"184\"><strong>Less than (-lt)<\/strong><\/td>\n<td style=\"text-align: center;width: 35.5392%\" width=\"216\">[[ $number1 -lt $number2 ]]\nor<br \/>\n[ $number1 -lt $number2 ]<\/td>\n<td style=\"text-align: center;width: 32.9657%\" width=\"200\">Returns true if the number1 is less than number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;width: 30.3922%\" width=\"184\"><strong>Equal to (-eq) <\/strong><\/td>\n<td style=\"text-align: center;width: 35.5392%\" width=\"216\">[[ $number1 -eq $number2 ]] or<br \/>\n[ $number1 -eq $number2 ]<\/td>\n<td style=\"text-align: center;width: 32.9657%\" width=\"200\">Returns true if the number1 is equal to number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;width: 30.3922%\" width=\"184\"><strong>Not Equal to (ne) <\/strong><\/td>\n<td style=\"text-align: center;width: 35.5392%\" width=\"216\">[[ $number1 -ne $number2 ]] or<br \/>\n[ $number1 -ne $number2 ]<\/td>\n<td style=\"text-align: center;width: 32.9657%\" width=\"200\">Returns true if the number1 is not equal to number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;width: 30.3922%\" width=\"184\"><strong>Greater than or Equal to (ge) <\/strong><\/td>\n<td style=\"text-align: center;width: 35.5392%\" width=\"216\">[[ $number1 -ge $number2 ]] or<br \/>\n[ $number1 -ge $number2 ]<\/td>\n<td style=\"text-align: center;width: 32.9657%\" width=\"200\">Returns true if the number1 is greater than or equal to number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;width: 30.3922%\" width=\"184\"><strong>Less than or Equal to (le) <\/strong><\/td>\n<td style=\"text-align: center;width: 35.5392%\" width=\"216\">[[ $number1 -le $number2 ]] or<br \/>\n[ $number1 -le $number2 ]<\/td>\n<td style=\"text-align: center;width: 32.9657%\" width=\"200\">Returns true if the number1 is less than and equal to number2.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/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> Make sure to double-check the syntax to prevent the bash script from making syntax errors.<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"2_Compare_Numbers_in_Bash_Using_Double_Parenthesis\"><\/span>2. Compare Numbers in Bash Using Double Parenthesis<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Double parenthesis is a<strong> built-in<\/strong> arithmetic feature that offers a more flexible syntax to compare numbers in Bash compared to square braces. Moreover, it does not show any errors, even when the space within the parenthesis is removed. In this section, I will be discussing <strong>6<\/strong> comparison operators. Let&#8217;s review them.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_Greater_Than_Sign_%E2%80%9C%3E%E2%80%9D\"><\/span>Using Greater Than Sign \u201c&gt;\u201d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To compare numbers in bash,\u00a0 you can apply greater than sign <code class=\"\" data-line=\"\">&gt;<\/code> inside the double parenthesis of the <code class=\"\" data-line=\"\">if<\/code> condition. The condition will come up with a <strong>true<\/strong> result if the 1st input number is greater than the 2nd input number. Now. let\u2019s see the bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif (( $number1 &gt; $number2 ));\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is greater than number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not greater than number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">If the number1 is <strong>greater than<\/strong> number2, it will return <strong>true<\/strong> expression &#8220;Number1 is greater than number2&#8221;. On the other hand, it will return the <strong>false<\/strong> code block.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26080\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.output-of-gt-opt.sh_.png\" alt=\"using greater than sign option to compare numbers in bash\" width=\"566\" height=\"386\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.output-of-gt-opt.sh_.png 566w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/7.output-of-gt-opt.sh_-300x205.png 300w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/p>\n<p style=\"text-align: justify;\">This image demonstrates that &#8220;Number1 is greater than number2&#8221; after writing <strong>number1=5<\/strong> and <strong>number2=3<\/strong>. Conversely, <strong>number1=4 <\/strong>and<strong> number2=8<\/strong>, indicate that &#8220;Number1 is not greater than number2&#8221; as 4 is less than 8.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_the_Less_Than_Sign_%E2%80%9C\"><\/span>Using the Less Than Sign \u201c&lt;\u201d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The less-than sign <code class=\"\" data-line=\"\">&lt;<\/code> compares if a number is less than the other. Like -le, it displays <strong>if block code<\/strong> when the 1st operand is less than the 2nd one.<\/p>\n<p style=\"text-align: justify;\">To compare numbers with less than sign, use this syntax <code class=\"\" data-line=\"\">(( $number1 &lt; $number2 ))<\/code> within the <code class=\"\" data-line=\"\">if<\/code> condition. Here\u2019s how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif (( $number1 &lt; $number2 ));\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is less than number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not less than number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">If the <strong>number1<\/strong> is <strong>less than<\/strong> number2, it will return <strong>true<\/strong> expression. Otherwise, it will execute the <strong>false<\/strong> code block.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26081\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/8.output-of-lt-opt.sh_.png\" alt=\"using less than sign option to compare numbers in bash\" width=\"519\" height=\"386\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/8.output-of-lt-opt.sh_.png 519w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/8.output-of-lt-opt.sh_-300x223.png 300w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/p>\n<p style=\"text-align: justify;\">You can see in this picture that if you take <strong>number1=3<\/strong> and <strong>number2=2<\/strong> as input numbers, it shows &#8220;Number1 is not less than number2&#8221; as 3 is greater than 2. But if you take <strong>number1=4 <\/strong>and<strong> number2=8<\/strong>, it shows &#8220;Number1 is less than number2&#8221; as 4 is less than 8.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_Equal_to_Operator_%E2%80%9C%E2%80%9D\"><\/span>Using Equal to Operator \u201c==\u201d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>An equal sign <code class=\"\" data-line=\"\">==<\/code> checks whether the numbers are equal. Here\u2019s a bash script for this:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif ((number1 == number2)); then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is equal to number2&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not equal to number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">Here, the equal operator <code class=\"\" data-line=\"\">==<\/code> indicates the equality between the number1 and number2. If the number1 is <strong>equal to<\/strong> number2, it will execute<strong> if block <\/strong>expression &#8220;Number1 is equal to number2&#8221;. Contrarily, it will return the <strong>else<\/strong> code block.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26082\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/9.output-of-eq-opt.sh_.png\" alt=\"using equal to sign option to compare numbers in bash\" width=\"504\" height=\"385\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/9.output-of-eq-opt.sh_.png 504w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/9.output-of-eq-opt.sh_-300x229.png 300w\" sizes=\"(max-width: 504px) 100vw, 504px\" \/><\/p>\n<p style=\"text-align: justify;\">As you can see, after giving both input numbers as <strong>5<\/strong>, it shows &#8220;Number1 is equal to number2&#8221;. While giving different input numbers <strong>5<\/strong> and<strong> 6<\/strong>, it shows &#8220;Number1 is not equal to number2&#8221;.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_Not_Equal_To_Sign_%E2%80%9C%E2%80%9D\"><\/span>Using Not Equal To Sign \u201c!=\u201d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The not equal sign <code class=\"\" data-line=\"\">!=<\/code> inside the double brackets <strong>((<\/strong>, tests if the two input numbers are not equal. Based on this condition, it gives <strong>true<\/strong> or <strong>false<\/strong> outcomes.<\/p>\n<p style=\"text-align: justify;\">To check the inequality between the numbers, write <code class=\"\" data-line=\"\">[ $number1 != $number2 ]<\/code> in the bash script. Here\u2019s how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif [ $number1 != $number2 ];\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not equal to number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is equal to number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">When the number1 is <strong>not equal to<\/strong> number2, it prints the <strong>if block<\/strong> code. Otherwise, it executes the <strong>else<\/strong> code block &#8220;Number1 is equal to number2&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26083\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/10.output-of-ne-opt.sh_.png\" alt=\"using not equal to sign option to compare numbers in bash\" width=\"502\" height=\"387\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/10.output-of-ne-opt.sh_.png 502w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/10.output-of-ne-opt.sh_-300x231.png 300w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/p>\n<p style=\"text-align: justify;\">Since both number is <strong>3<\/strong>, it shows that &#8220;Number1 is equal to number2&#8221;. While putting different input numbers <strong>2 <\/strong>and <strong>3<\/strong>, it shows &#8220;Number1 is not equal to number2&#8221;.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_Greater_Or_Equal_To_Sign_%E2%80%9C%3E%E2%80%9D\"><\/span>Using Greater Or Equal To Sign \u201c&gt;=\u201d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">This greater than or equal operator executes the true output If the 1st input integer is <strong>greater than<\/strong> or <strong>equal to<\/strong> the 2nd one.<\/p>\n<p style=\"text-align: justify;\">To compare numbers in bash, you can use the <code class=\"\" data-line=\"\">&gt;=<\/code> sign within the double brackets. Let&#8217;s take a look at how it works.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif (( $number1 &gt;= $number2 ));\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is greater than and equal to number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not greater than and equal to number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">This <strong>greater than<\/strong> and <strong>equal<\/strong> sign <code class=\"\" data-line=\"\">&gt;=<\/code> checks whether the number1 is greater than or equal to number2. If the condition is <strong>true<\/strong>, the script executes the <strong>if block<\/strong> expression. Otherwise, it executes the <strong>else block<\/strong> expression.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26084\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/11.output-of-ge-opt.sh_.png\" alt=\"using greater than or equal to sign option to compare numbers in bash\" width=\"700\" height=\"349\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/11.output-of-ge-opt.sh_.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/11.output-of-ge-opt.sh_-300x150.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p style=\"text-align: justify;\">Here, when both input numbers are <strong>15<\/strong>, it shows &#8220;Number1 is greater than and equal to number2&#8221;. But after taking <strong>number1=15<\/strong> which is <strong>less than<\/strong> the <strong>number2=16<\/strong>. In this case, it executes &#8220;Number1 is not greater than and equal to number2&#8221;.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_Less_Or_Equal_to_Sign_%E2%80%9C\"><\/span>Using Less Or Equal to Sign \u201c&lt;=\u201d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The less than and equal sign <code class=\"\" data-line=\"\">&lt;=<\/code> works like the <code class=\"\" data-line=\"\">-le<\/code> option discussed in the previous section. To compare numbers with <code class=\"\" data-line=\"\">&lt;=<\/code>, use <code class=\"\" data-line=\"\">(( $number1 &lt;= $number2 ))<\/code> to get the actual output. Here\u2019s the bash script for this:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter an input number1: &quot;\nread number1\necho &quot;Enter an input number2: &quot;\nread number2\nif (( $number1 &lt;= $number2 ));\n\u00a0then\n\u00a0\u00a0\u00a0 echo &quot;Number1 is less than and equal to number2&quot;\n\u00a0else\n\u00a0\u00a0\u00a0 echo &quot;Number1 is not less than and equal to number2&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">If the condition is <strong>true<\/strong>, the script executes the <strong>if block<\/strong> expression. Otherwise, it executes the <strong>else block<\/strong> expression &#8220;Number1 is not less than and equal to number2&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26085\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/12.output-of-le-opt.sh_.png\" alt=\"using less than and equal to sign option to compare numbers in bash\" width=\"700\" height=\"372\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/12.output-of-le-opt.sh_.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/12.output-of-le-opt.sh_-300x159.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p style=\"text-align: justify;\">After executing the script and taking both input numbers as <strong>25<\/strong>, it shows &#8220;Number1 is less than and equal to number2&#8221;. With the input <strong>number1=25<\/strong> and <strong>number2=24<\/strong>, it displays &#8220;Number1 is not less than and equal to number2&#8221;.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Summary_of_Operators_for_Double_Parenthesis\"><\/span>Summary of Operators for Double Parenthesis<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Comparison operators used with double parentheses in the bash script are as follows:<\/p>\n<div class=\"su-table su-table-responsive su-table-alternate su-table-fixed\">\n<table style=\"width: 76.6982%;height: 533px\" width=\"0\">\n<tbody>\n<tr>\n<th width=\"184\"><strong>Comparison Operator<\/strong><\/th>\n<th width=\"216\"><strong>Syntax<\/strong><\/th>\n<th width=\"200\"><strong>Description<\/strong><\/th>\n<\/tr>\n<tr>\n<td style=\"text-align: center\" width=\"184\"><strong>Greater than (&gt;) <\/strong><\/td>\n<td style=\"text-align: center\" width=\"216\">(( $number1 &gt; $number2 ))<\/td>\n<td style=\"text-align: center\" width=\"200\">Returns true if the number1 is greater than number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\" width=\"184\"><strong>Less than (&lt;)<\/strong><\/td>\n<td style=\"text-align: center\" width=\"216\">(( $number1 &lt; $number2 ))<\/td>\n<td style=\"text-align: center\" width=\"200\">Returns true if the number1 is less than number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\" width=\"184\"><strong>Equal to (==) <\/strong><\/td>\n<td style=\"text-align: center\" width=\"216\">(( $number1 == $number2 ))<\/td>\n<td style=\"text-align: center\" width=\"200\">Returns true if the number1 is equal to number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\" width=\"184\"><strong>Not equal to (!=) <\/strong><\/td>\n<td style=\"text-align: center\" width=\"216\">(( $number1 != $number2 ))<\/td>\n<td style=\"text-align: center\" width=\"200\">Returns true if the number1 is not equal to number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\" width=\"184\"><strong>Greater than or Equal to (&gt;=) <\/strong><\/td>\n<td style=\"text-align: center\" width=\"216\">(( $number1 &gt;= $number2 ))<\/td>\n<td style=\"text-align: center\" width=\"200\">Returns true if the number1 is greater than or equal to number2.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\" width=\"184\"><strong>Less than or Equal to (&lt;=) <\/strong><\/td>\n<td style=\"text-align: center\" width=\"216\">(( $number1 &lt;= $number2 ))<\/td>\n<td style=\"text-align: center\" width=\"200\">Returns true if the number1 is less than and equal to number2.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\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 this article, I have showed <strong>two approaches<\/strong>, along with <strong>12<\/strong> different operators, for comparing integer numbers in the if else statement in bash. Certain operators demand <strong>double parentheses<\/strong>, whereas others require <strong>square brackets<\/strong>. To make sure you are using the right operator with the right bracket, review each step thoroughly. Good luck to you.<\/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_compare_strings_in_bash\"><\/span>How to compare strings in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can compare strings using comparison operators like greater than (<strong>&gt;<\/strong>), equal to (<strong>=<\/strong>), not equal to (<strong>!=<\/strong>), and less than (<strong>&lt;<\/strong>). In addition, you can apply <code class=\"\" data-line=\"\">-z<\/code> and <code class=\"\" data-line=\"\">-n<\/code> options to do this task.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_use_%E2%80%98regex_operator_to_compare_numbers_in_bash\"><\/span>Can I use \u2018regex\u2019 operator to compare numbers in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">No, you can not use the<strong> regular expression<\/strong> <code class=\"\" data-line=\"\">=~<\/code> to compare numbers in Bash. You can apply this operator within the if condition to compare <strong>strings<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_can_I_compare_two_floating_point_numbers_in_bash\"><\/span>How can I compare two floating point numbers in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To compare floating numbers in bash, you can use the bc command in conjunction with the <code class=\"\" data-line=\"\">==<\/code> operator inside the <strong>if<\/strong> statement. Check this bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nnum1=3.1415\nnum2=3.1416\n\n# Use bc for floating-point comparison\nif [ $(echo &quot;$num1 == $num2&quot; | bc -l) -eq 1 ]; then\n\u00a0\u00a0\u00a0 echo &quot;Numbers are equal&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;Numbers are not equal&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">This script uses the command <code class=\"\" data-line=\"\">bc -l<\/code> to compare the numbers. If the result is equal to <strong>1<\/strong>, then the numbers are the same. Otherwise, they&#8217;re not.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_compare_three_numbers_in_Linux\"><\/span>Can I compare three numbers in Linux?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Yes, definitely. You can use the logical <strong>AND (&amp;&amp;) <\/strong>operator inside the <strong>if <\/strong>condition to compare <strong>three<\/strong> numbers in Linux. To check whether the <strong>num1<\/strong> is <strong>greater than<\/strong> the <strong>num2<\/strong> and <strong>num3<\/strong>, use this syntax in your bash script: <code class=\"\" data-line=\"\">if [ $num1 -gt $num2 ] &amp;&amp; [ $num1 -gt $num3 ]<\/code>.<\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"How to compare strings in bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"You can compare strings using comparison operators like greater than (>), equal to (=), not equal to (!=), and less than (<). In addition, you can apply -z and -n options to do this task.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Can I use \u2018regex\u2019 operator to compare numbers in bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"No, you can not use the regular expression =~ to compare numbers in Bash. You can apply this operator within the if condition to compare strings.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Can I compare three numbers in Linux?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Yes, definitely. You can use the logical AND (&#038;&#038;) operator inside the if condition to compare three numbers in Linux. To check whether the num1 is greater than the num2 and num3, use this syntax in your bash script: if [ $num1 -gt $num2 ] &#038;&#038; [ $num1 -gt $num3 ].\"\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\/conditional-statements\/if-else\/if-variable-exists\/\" target=\"_blank\" rel=\"noopener\">Check If a Variable Exists in Bash If Statement<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/if-argument-exists\/\" target=\"_blank\" rel=\"noopener\">Check If An Input Argument Exists in Bash [4 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/if-contains-string\/\" target=\"_blank\" rel=\"noopener\">Check If a String Contains Substring, Number &amp; Letter in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/if-string-not-empty\/\" target=\"_blank\" rel=\"noopener\">Check If a String is Empty or Not in Bash [5 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-strings\/\" target=\"_blank\" rel=\"noopener\">How to Compare Strings in Bash With if Statement [6 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/if-in-array\/\" target=\"_blank\" rel=\"noopener\">Check If Array Contains an Element in Bash [6 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/if-else-one-line\/\" target=\"_blank\" rel=\"noopener\">Bash if-else Condition in One-Line [2 Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/grep\/\" target=\"_blank\" rel=\"noopener\">Using grep in if Statement in Bash [4 Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/regex\/\" target=\"_blank\" rel=\"noopener\">How to Use Regex in Bash If Condition? [4 Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/rm-if-exists\/\" target=\"_blank\" rel=\"noopener\">Bash rm If Exists [All Case Explained]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/dollar-sign\/\" target=\"_blank\" rel=\"noopener\">What is \u2018$?\u2019 in the Bash if Statement? [8 Examples]<\/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;If Else 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\/conditional-statements\/if-else\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/\" target=\"_blank\" rel=\"noopener\">If Else in Bash<\/a><\/span>\u00a0| <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Conditional Statements&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\/conditional-statements\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/\" target=\"_blank\" rel=\"noopener\">Bash Conditional Statements<\/a><\/span> | <span data-sheets-root=\"1\" 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;26071&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;5&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;4&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;4\\\/5 - (5 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Compare Numbers in Bash With If Statement [2 Methods]&quot;,&quot;width&quot;:&quot;113.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: 113.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            4\/5 - (5 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Compare Numbers in Bash scripting\u00a0is essential for a wide range of tasks, including arithmetic calculations and logical decisions. Therefore, it &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Compare Numbers in Bash With If Statement [2 Methods]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#more-26071\" aria-label=\"Read more about How to Compare Numbers in Bash With If Statement [2 Methods]\">Read more<\/a><\/p>\n","protected":false},"author":314908,"featured_media":26086,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[167],"class_list":["post-26071","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-if-else-statement","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 Compare Numbers in Bash With If Statement [2 Methods] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"This article contains 2 approaches including 12 comparison operators to compare numbers in bash with if statement.\" \/>\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\/conditional-statements\/if-else\/compare-numbers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Compare Numbers in Bash With If Statement [2 Methods] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"This article contains 2 approaches including 12 comparison operators to compare numbers in bash with if statement.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/mitalimostakim.mou\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-06T04:24:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-04T03:18:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Bash-Compare-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=\"Mitu Akter Mou\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mitu Akter Mou\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/\"},\"author\":{\"name\":\"Mitu Akter Mou\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/54b35370776bb6a79376ea0135412689\"},\"headline\":\"How to Compare Numbers in Bash With If Statement [2 Methods]\",\"datePublished\":\"2023-11-06T04:24:53+00:00\",\"dateModified\":\"2023-12-04T03:18:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/\"},\"wordCount\":2285,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Bash-Compare-Numbers.png\",\"keywords\":[\"if else statement\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/\",\"name\":\"How to Compare Numbers in Bash With If Statement [2 Methods] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Bash-Compare-Numbers.png\",\"datePublished\":\"2023-11-06T04:24:53+00:00\",\"dateModified\":\"2023-12-04T03:18:29+00:00\",\"description\":\"This article contains 2 approaches including 12 comparison operators to compare numbers in bash with if statement.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-numbers\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Bash-Compare-Numbers.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Bash-Compare-Numbers.png\",\"width\":400,\"height\":400,\"caption\":\"bash compare numbers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/compare-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 Conditional Statements\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"If Else in Bash\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Compare Numbers in Bash With If Statement [2 Methods]\"}]},{\"@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\\\/54b35370776bb6a79376ea0135412689\",\"name\":\"Mitu Akter Mou\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mitu-Akter-Mou-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mitu-Akter-Mou-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mitu-Akter-Mou-II-96x96.png\",\"caption\":\"Mitu Akter Mou\"},\"description\":\"Hello, This is Mitu Akter Mou, currently working as a Linux Content Developer Executive at SOFTEKO for the Linuxsimply project. I hold a bachelor's degree in Biomedical Engineering from Khulna University of Engineering &amp; Technology (KUET). Experiencing new stuff and gathering insights from them seems very happening to me. My goal here is to simplify the life of Linux users by making creative articles, blogs, and video content for all of them. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/mitalimostakim.mou\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/mitu-akter-mou-915537198\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/mou\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Compare Numbers in Bash With If Statement [2 Methods] - LinuxSimply","description":"This article contains 2 approaches including 12 comparison operators to compare numbers in bash with if statement.","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\/conditional-statements\/if-else\/compare-numbers\/","og_locale":"en_US","og_type":"article","og_title":"How to Compare Numbers in Bash With If Statement [2 Methods] - LinuxSimply","og_description":"This article contains 2 approaches including 12 comparison operators to compare numbers in bash with if statement.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/mitalimostakim.mou\/","article_published_time":"2023-11-06T04:24:53+00:00","article_modified_time":"2023-12-04T03:18:29+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Bash-Compare-Numbers.png","type":"image\/png"}],"author":"Mitu Akter Mou","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mitu Akter Mou","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/"},"author":{"name":"Mitu Akter Mou","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/54b35370776bb6a79376ea0135412689"},"headline":"How to Compare Numbers in Bash With If Statement [2 Methods]","datePublished":"2023-11-06T04:24:53+00:00","dateModified":"2023-12-04T03:18:29+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/"},"wordCount":2285,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Bash-Compare-Numbers.png","keywords":["if else statement"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/","name":"How to Compare Numbers in Bash With If Statement [2 Methods] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Bash-Compare-Numbers.png","datePublished":"2023-11-06T04:24:53+00:00","dateModified":"2023-12-04T03:18:29+00:00","description":"This article contains 2 approaches including 12 comparison operators to compare numbers in bash with if statement.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-numbers\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Bash-Compare-Numbers.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/11\/Bash-Compare-Numbers.png","width":400,"height":400,"caption":"bash compare numbers"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/compare-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 Conditional Statements","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/"},{"@type":"ListItem","position":4,"name":"If Else in Bash","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/"},{"@type":"ListItem","position":5,"name":"How to Compare Numbers in Bash With If Statement [2 Methods]"}]},{"@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\/54b35370776bb6a79376ea0135412689","name":"Mitu Akter Mou","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mitu-Akter-Mou-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mitu-Akter-Mou-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mitu-Akter-Mou-II-96x96.png","caption":"Mitu Akter Mou"},"description":"Hello, This is Mitu Akter Mou, currently working as a Linux Content Developer Executive at SOFTEKO for the Linuxsimply project. I hold a bachelor's degree in Biomedical Engineering from Khulna University of Engineering &amp; Technology (KUET). Experiencing new stuff and gathering insights from them seems very happening to me. My goal here is to simplify the life of Linux users by making creative articles, blogs, and video content for all of them. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/mitalimostakim.mou\/","https:\/\/www.linkedin.com\/in\/mitu-akter-mou-915537198\/"],"url":"https:\/\/linuxsimply.com\/author\/mou\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/26071","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\/314908"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=26071"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/26071\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/26086"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=26071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=26071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=26071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}