{"id":24071,"date":"2023-10-11T08:39:36","date_gmt":"2023-10-11T08:39:36","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=24071"},"modified":"2024-02-08T07:19:07","modified_gmt":"2024-02-08T07:19:07","slug":"if-else-in-bash","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/","title":{"rendered":"If Else in Bash"},"content":{"rendered":"<p style=\"text-align: justify;\">Controlling the flow of statements execution in the bash program is a fundamental task of decision-making. Therefore, in the bash script, the <strong>if else <\/strong>conditional statement is used to perform the execution of a set of statements by checking the <strong>conditions<\/strong>. In this article, I will walk you through a complete guide to the if-else statement including syntax and various examples of it. Moreover, nested if-else is also discussed here. Let\u2019s start the discussion.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/Practice_Files_if-else-in-bash.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 Use &#8220;If else&#8221; Statement 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\/#Basics_of_If_Statement_in_Bash\" >Basics of If Statement in Bash<\/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\/#Basics_of_If_Else_Statement_in_Bash\" >Basics of If Else Statement in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#Basics_of_Nested_If_Else_Statements_in_Bash\" >Basics of Nested If Else Statements in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#Bash_If_Else_Operators\" >Bash If Else Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#How_to_Use_If_Else_Statement_in_Bash\" >How to Use If Else Statement in Bash<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#Example_01_Checking_if_a_Number_is_Even_or_Odd_With_If_Else_in_Bash\" >Example 01: Checking if a Number is Even or Odd With If Else in Bash<\/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\/#Example_02_Checking_if_a_Number_is_Positive_Negative_or_Zero_With_If_Else\" >Example 02: Checking if a Number is Positive, Negative, or Zero With If Else<\/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\/#Example_03_Nested_If_Else_Statements\" >Example 03: Nested If Else Statements<\/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\/#Example_04_Checking_the_Number_of_Arguments_With_If_Else\" >Example 04: Checking the Number of Arguments With If Else<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#Example_05_Checking_if_Creation_of_a_File_is_Successful_With_If_Else\" >Example 05: Checking if Creation of a File is Successful With If Else<\/a><\/li><li class='ez-toc-page-1 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\/#Example_06_If_Else_Statement_With_Logical_%E2%80%9CAND%E2%80%9D_Operator_in_Bash\" >Example 06: If Else Statement With Logical &#8220;AND&#8221; Operator in Bash<\/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\/#Example_07_If_Else_Statement_With_Logical_%E2%80%9COR%E2%80%9D_Operator\" >Example 07: If Else Statement With Logical &#8220;OR&#8221; Operator<\/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\/#Example_08_Concatenating_Strings_With_If_Else_in_Bash\" >Example 08: Concatenating Strings With If Else 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\/conditional-statements\/if-else\/#Example_09_Arithmetic_Operation_With_Variables_Using_If_Else\" >Example 09: Arithmetic Operation With Variables Using If Else<\/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\/#Example_10_Checking_If_a_File_Exists_With_If_Else\" >Example 10: Checking If a File Exists With If Else<\/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\/#Example_11_Using_If_Else_to_Verify_Password_in_Bash\" >Example 11: Using If Else to Verify Password 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-17\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#Conclusion\" >Conclusion<\/a><\/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\/#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-19\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#What_is_the_else_if_statement_in_Bash\" >What is the else if statement in Bash?<\/a><\/li><li class='ez-toc-page-1 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\/#Is_an_if-else_statement_a_function\" >Is an if-else statement a function?<\/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\/#Is_there_Elif_in_bash\" >Is there Elif 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\/#What_does_mean_in_bash\" >What does @$ mean 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\/#What_does_mean_in_bash-2\" >What does == mean in bash?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Basics_of_If_Statement_in_Bash\"><\/span>Basics of If Statement in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>if<\/strong> is a <strong>conditional statement<\/strong> that is used to make decisions in the <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/introduction\/what-is-bash-scripting\/\" target=\"_blank\" rel=\"noopener\">bash script<\/a><\/u><\/strong>. This statement checks whether the condition is <strong>true<\/strong> or<strong> false<\/strong>. With an if statement you can set multiple conditions as well.<\/p>\n<p>The basic syntax of the <strong>if<\/strong> expression is:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">if [condition]; then\n# execution code block\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p><strong>if<\/strong>: Starts the if operation.<\/p>\n<p><strong>[condition]<\/strong>: The condition is enclosed with square brackets \u2018[ ]\u2019.<\/p>\n<p><strong>then<\/strong>: Separates the condition from the execution code block.<\/p>\n<p><strong># execution code block:<\/strong> If the condition is true, this code block will be executed.<\/p>\n<p><strong>fi<\/strong>: Ends the if operation.<\/p>\n<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Basics_of_If_Else_Statement_in_Bash\"><\/span>Basics of If Else Statement in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">The if-else is a conditional statement used for conditional branching in <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">bash scripting<\/a><\/u><\/strong>. When any condition is set using if-else, it will verify the condition. If the condition is <strong>true<\/strong>, it will execute the <strong>if block<\/strong> statement. When the condition is <strong>false<\/strong>, it will execute the <strong>else block<\/strong> statement. See the flow diagram of the if-else statement:<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-24081\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/1.if-else-flow-chart.png\" alt=\"flow diagram of the if else statement in bash\" width=\"424\" height=\"418\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/1.if-else-flow-chart.png 424w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/1.if-else-flow-chart-300x296.png 300w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/p>\n<p style=\"text-align: justify;\">The basic syntax of an if-else statement is:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">if [ condition ]; then\n\u00a0\u00a0\u00a0 # execute the code if the condition is true\nelse\n\u00a0\u00a0\u00a0 # execute the code if the condition is false\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p><strong>if<\/strong>: Starts the operation.<\/p>\n<p><strong>[condition]<\/strong>: The condition is enclosed with square brackets \u2018[ ]\u2019.<\/p>\n<p><strong>then<\/strong>: Separates the condition from the execution code block.<\/p>\n<p><strong># execute the code if the condition is true<\/strong>: If the condition is true, it will execute this code.<\/p>\n<p><strong>else: <\/strong>Execute another code if the condition is false.<\/p>\n<p><strong># execute the code if the condition is false<\/strong>: If the condition is false, it will execute this code.<\/p>\n<p><strong>fi<\/strong>: Ends the operation.<\/p>\n<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Basics_of_Nested_If_Else_Statements_in_Bash\"><\/span>Basics of Nested If Else Statements in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Nested if else<\/strong> statements are used to handle <strong>complex conditions<\/strong>. It will allow you to explore more precise decision-making by handling <strong>multiple<\/strong> conditions.<\/p>\n<p>The basic syntax of the <strong>nested if else <\/strong>is:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">if [1st condition]; then\n\u00a0\u00a0\u00a0 # statement1 will be executed if 1st condition is true\n\u00a0\u00a0\u00a0 if [2nd condition]; then\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # statement2 will be executed if both 1st condition and 2nd condition are true\n\u00a0\u00a0\u00a0 else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # statement3 will be executed if 1st condition is true and 2nd condition is false\n\u00a0\u00a0\u00a0 fi\nelse\n\u00a0\u00a0\u00a0 # statement4 will be executed if 1st condition is false\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>If the <strong>1st condition<\/strong> is true then the code in the<strong> satement1 <\/strong>will be executed. When <strong>both conditions<\/strong> are true the <strong>statement2<\/strong>\u00a0 which is <strong>nested<\/strong> under the first if statement will be executed. Otherwise, the<strong> statement3<\/strong> will be executed. However, if the <strong>first condition<\/strong> is false, the <strong>last else block<\/strong> code <strong>statement4<\/strong> will be executed.<\/p>\n<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Bash_If_Else_Operators\"><\/span>Bash If Else Operators<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In bash scripting, numerous operators are under the<strong> if else<\/strong> statement to perform multiple types of operations. Some of the commonly used operators are provided in the following table:<\/p>\n<div class=\"su-table su-table-responsive su-table-alternate su-table-fixed\">\n<table style=\"width: 100%\" width=\"100%\">\n<tbody>\n<tr>\n<th style=\"width: 29.1517%\" width=\"301\"><strong>Operator<\/strong><\/th>\n<th style=\"width: 71.656%\" width=\"301\"><strong>Function<\/strong><\/th>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-eq<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the integers are equal.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-ne<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the integers are not equal.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-gt<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the integer1 is greater than integer2.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-lt<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the integer1 is less than integer2.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-ge<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the integer1 is greater than and equal to integer2.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-le<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the integer1 is less than and equal to integer2.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>=<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the strings are equal.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>!=<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the strings are not equal.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>&amp;&amp;<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Multiple commands connected by the AND operator will only execute if all the conditions are true.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>| |<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Multiple commands connected by the OR operator will only execute if at least one of the conditions is true.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-f<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a regular file exists.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-d<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a directory exists.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-e<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a file exists.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-h<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a file exists that is a symbolic link.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-s<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a non-empty file exists.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-r<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a file exists that is readable.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-w<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a file exists that is writable.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-x<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a file exists that is executable.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-n<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if the length of a variable is greater than zero.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;width: 29.1517%;text-align: center\" width=\"301\"><strong>-z<\/strong><\/td>\n<td style=\"vertical-align: middle;width: 71.656%\" width=\"301\">Checks if a string is null.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Use_If_Else_Statement_in_Bash\"><\/span>How to Use If Else Statement in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">If-else statement can be used to perform different operations over numbers, arguments, strings, and arrays. Moreover, you can use <strong>nested<\/strong> if else to operate multiple conditions. Now, I will show you <strong>11 examples<\/strong> of if else statement in the following section. An example of <strong>nested if else<\/strong> is also included here.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_01_Checking_if_a_Number_is_Even_or_Odd_With_If_Else_in_Bash\"><\/span>Example 01: Checking if a Number is Even or Odd With If Else in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Checking a number if it is <strong>even or odd<\/strong> is an easy and simple task that helps you understand the <strong>function<\/strong> of an if else statement. The following code will show you how to <strong>use<\/strong> if else to find an even or odd number:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter a number: &quot;\nread number\nif [ $((number % 2)) -eq 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;even number&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;odd number&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>Here, in <code class=\"\" data-line=\"\">#!\/bin\/bash<\/code><strong>, \u2018#!\u2019<\/strong> is called <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/what-is-shebang\/\" target=\"_blank\" rel=\"noopener\"><strong><u>shebang <\/u><\/strong><u>or <strong>hashbang<\/strong><\/u><\/a>. It indicates the interpreter to be used for executing the script, in this case, it\u2019s <strong>Bash<\/strong>. When you put any number as an <strong>input<\/strong>, the <strong>read<\/strong> common reads the input number. The <strong>% <\/strong>operator divides the input number by<strong> 2<\/strong> and checks if there is any<strong> remainder<\/strong>. If it does not find any remainder, the number is <strong>even<\/strong> and prints the <strong>if code block<\/strong> otherwise the number is <strong>odd<\/strong> and prints the <strong>else code block<\/strong>. The <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\">echo command<\/a><\/u> <\/strong>echoes the quoted message.<\/p>\n<\/div><\/div>\n<img decoding=\"async\" class=\"aligncenter size-full wp-image-24083\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/3.output-of-even-odd.png\" alt=\"checking if a number is even or odd\" width=\"427\" height=\"255\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/3.output-of-even-odd.png 427w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/3.output-of-even-odd-300x179.png 300w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/p>\n<p style=\"text-align: justify;\">In this image, you can see that as an input, <strong>number 10<\/strong> is entered and the output shows it is an <strong>even number<\/strong>. When the input number is <strong>11<\/strong>, it shows that this is an <strong>odd number<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_02_Checking_if_a_Number_is_Positive_Negative_or_Zero_With_If_Else\"><\/span>Example 02: Checking if a Number is Positive, Negative, or Zero With If Else<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Whether a number is <strong>positive, negative, or zero,<\/strong> can be checked easily using the <strong>if-else<\/strong> conditional statement. If a number is <strong>greater<\/strong> than zero, it will be a <strong>positive<\/strong> number and the number which is <strong>less<\/strong> than zero is a <strong>negative<\/strong> number.<\/p>\n<p style=\"text-align: justify;\">To check whether a number is positive, negative or zero with an &#8216;if else statement&#8217;, follow the code given below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter a number: &quot;\nread number\nif [ $number -gt 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;It is a positive number.&quot;\nelif [ $number -lt 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;It is a negative number.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;It is a zero.&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>In this bash script, if you enter a number, it will verify whether the assigned number is <strong>greater<\/strong> than <strong>0<\/strong> with the <code class=\"\" data-line=\"\">-gt<\/code> option. If the condition is <strong>true<\/strong> it will print <strong>&#8220;It is a positive number.&#8221;<\/strong> Then I set another condition in the <strong>elif<\/strong> block that uses the <strong>-lt<\/strong> option to check whether the number is <strong>less<\/strong> than <strong>0<\/strong>. If the condition is <strong>true<\/strong> it will print <strong>&#8220;It is a negative number.&#8221; <\/strong>Finally, it prints the <strong>else<\/strong> block code <strong>&#8220;It is a zero.&#8221;<\/strong> if both conditions are <strong>false<\/strong>.<\/div><\/div>\n<img decoding=\"async\" class=\"aligncenter size-full wp-image-24084\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/4.output-of-positive-negative-zero.png\" alt=\"checking if a number is positive, negative or zero\" width=\"493\" height=\"388\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/4.output-of-positive-negative-zero.png 493w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/4.output-of-positive-negative-zero-300x236.png 300w\" sizes=\"(max-width: 493px) 100vw, 493px\" \/>When you enter <strong>2<\/strong>, it shows that it is a <strong>positive number<\/strong>. If you enter <strong>-3<\/strong>, it shows it is a <strong>negative number<\/strong>. Again if you put<strong> 0<\/strong>, the output shows it is a<strong> zero<\/strong>. You can enter any number to check whether the number is positive, negative, or zero.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_03_Nested_If_Else_Statements\"><\/span>Example 03: Nested If Else Statements<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Nested if-else statements in Bash are used to create more complex decision-making structures by including multiple levels of conditions. Here&#8217;s an example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter a number: &quot;\nread num\nif [ $num -gt 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;positive number.&quot;\n\u00a0\u00a0\u00a0 if [ $((num % 2)) -eq 0 ]; then\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;even number.&quot;\n\u00a0\u00a0\u00a0 else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;odd number.&quot;\n\u00a0\u00a0\u00a0 fi\nelse\n\u00a0\u00a0\u00a0 echo &quot;non-positive number.&quot;\n\u00a0\u00a0\u00a0 if [ $num -eq 0 ]; then\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;it is zero.&quot;\n\u00a0\u00a0\u00a0 else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;negative number.&quot;\n\u00a0\u00a0\u00a0 fi\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>After reading the input number with the <strong>read<\/strong> command, it checks whether the number is positive, negative, even, or add. If the number is <strong>greater<\/strong> than<strong> 0<\/strong>, it prints a <strong>&#8220;positive number.&#8221;<\/strong>. Another statement inside this block checks if the positive number is even or odd. After that, if the number is <strong>less<\/strong> than <strong>0<\/strong>, it prints a <strong>&#8220;non-positive number.&#8221;<\/strong>. Another if else statement checks if the number is <strong>equal <\/strong>to <strong>0 <\/strong>and prints <strong>&#8220;it is zero.&#8221;<\/strong> otherwise prints <strong>&#8220;negative number.&#8221;<\/strong>.<\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24085\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/5.output-of-nest.png\" alt=\"example of the nested if else statements\" width=\"425\" height=\"481\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/5.output-of-nest.png 425w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/5.output-of-nest-265x300.png 265w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/p>\n<p style=\"text-align: justify;\">After running the <strong>bash script, <\/strong>you can see a prompt asking you to enter a number. Entering the number <strong>3<\/strong> displays that it is a <strong>positive<\/strong> and an <strong>odd <\/strong>number. If you run the bash script again and enter <strong>-2<\/strong>, it displays that it\u2019s a <strong>non-positive<\/strong> and <strong>negative<\/strong> number. Similarly, you can check any number, it will execute the output based on the nested if else conditions.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_04_Checking_the_Number_of_Arguments_With_If_Else\"><\/span>Example 04: Checking the Number of Arguments With If Else<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In the <strong>bash script<\/strong>, arguments pass <strong>information <\/strong>to the bash script from the command line. Bash offers some special variables like<strong> $1, $2,<\/strong> and <strong>$3<\/strong> to pass the first, second, and third argument to the script respectively. The <strong>number<\/strong> of arguments is checked by the <strong>$#<\/strong> operator.<\/p>\n<p style=\"text-align: justify;\">Now, To know the number of arguments with if else statement, see the bash code given below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nif [ &quot;$#&quot; -eq 0 ]; then\n\u00a0\u00a0 \u00a0echo &quot;No arguments.&quot;\nelif [ &quot;$#&quot; -eq 1 ]; then\n\u00a0\u00a0\u00a0 echo &quot;1 argument.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;More than 1 argument.&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>Here, the <code class=\"\" data-line=\"\">$#<\/code>\u00a0operator checks the number of arguments provided by the users. When the number of arguments equals <strong>0<\/strong>, it executes <strong>if block<\/strong> and shows <strong>no arguments<\/strong>. If you put <strong>1<\/strong> argument, it executes the <strong>elif block<\/strong> and displays <strong>1 argument<\/strong>. If you write <strong>more than 1<\/strong> argument, it executes the <strong>else<\/strong> block.<\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24086\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/6.output-of-argument.png\" alt=\"checking the number of arguments in bash\" width=\"538\" height=\"192\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/6.output-of-argument.png 538w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/6.output-of-argument-300x107.png 300w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/p>\n<p style=\"text-align: justify;\">The printed output is shown in the picture. In the <strong>1st command<\/strong>, you can see <strong>nothing <\/strong>is written after the bash <strong>arg.sh<\/strong> script, so it shows <strong>no arguments<\/strong>. In the <strong>2nd<\/strong> and <strong>3rd<\/strong> command, <strong>ar1<\/strong> and <strong>ar1<\/strong>, <strong>ar2<\/strong> is entered respectively to <strong>check <\/strong>the number of arguments provided in the command line. If you enter more than <strong>2 arguments<\/strong>, it displays that there is <strong>more<\/strong> than 1 argument.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_05_Checking_if_Creation_of_a_File_is_Successful_With_If_Else\"><\/span>Example 05: Checking if Creation of a File is Successful With If Else<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">If you create a <strong>file<\/strong> and want to <strong>verify<\/strong> whether the task is <strong>successful<\/strong>, you can use <strong>$? <\/strong>operator in bash within the <strong>if else<\/strong> statement. You can also check if the <strong>network connection<\/strong> is successful, or the <strong>existence<\/strong> of a command using this special operator.<\/p>\n<p style=\"text-align: justify;\">To know whether a file is successfully created or not with if else statement, see the given code below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter the file name: &quot;\nread filename\n# Attempt to create the file\ntouch &quot;$filename&quot;\n# Check if the file creation was successful\nif [ $? -eq 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;File &#039;$filename&#039; created successfully.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;Failed to create the file &#039;$filename&#039;.&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>A prompt is taken to <strong>write <\/strong>a file name according to the users then a <strong>touch<\/strong> command is used to create that file. After creating the file, if the <code class=\"\" data-line=\"\">$?<\/code> is equal to <strong>zero<\/strong>, the file is created <strong>successfully<\/strong> otherwise <strong>fails<\/strong> to be created.<br \/>\n<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24087\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/7.output-of-file.sh_.png\" alt=\"checking if a file created successfully\" width=\"580\" height=\"130\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/7.output-of-file.sh_.png 580w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/7.output-of-file.sh_-300x67.png 300w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/p>\n<p style=\"text-align: justify;\">Here, the <strong>mou.txt<\/strong> file is created to check if it has been created successfully or not. After running the <strong>script<\/strong> and entering the <strong>file name<\/strong>, it shows that the file creation is <strong>successful<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_06_If_Else_Statement_With_Logical_%E2%80%9CAND%E2%80%9D_Operator_in_Bash\"><\/span>Example 06: If Else Statement With Logical &#8220;AND&#8221; Operator in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Generally, the <strong>AND operator<\/strong> is used to <strong>combine<\/strong> multiple conditions within an <strong>if else<\/strong> statement. If all the conditions are <strong>true<\/strong>, it will execute the <strong>if block<\/strong> output.<\/p>\n<p style=\"text-align: justify;\">The following code will combine <strong>two conditions<\/strong> with <strong>&amp;&amp;<\/strong> operator. See the code below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter your age: &quot;\nread age\necho &quot;Do you have a graduation certificate? (yes\/no): &quot;\nread certificate\nif [ &quot;$age&quot; -ge 23 ] &amp;&amp; [ &quot;$certificate&quot; = &quot;yes&quot; ]; then\n\u00a0\u00a0\u00a0 echo &quot;You are eligible to apply for this job.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;You are not eligible to apply for this job.&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">Here, 1st prompt is used to <strong>enter age<\/strong> and the 2nd one is to take <strong>yes or no<\/strong> answer. Within the<strong> if <\/strong>condition, two conditions are taken using the <code class=\"\" data-line=\"\">&amp;&amp;<\/code> operator. If both conditions are <strong>true,<\/strong> it displays<strong> &#8220;You are eligible to apply for this job.&#8221;<\/strong> on the other hand, it will print the<strong> else block.<\/strong><\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24088\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/8.output-of-AND-operator.png\" alt=\"AND operator function within if else\" width=\"700\" height=\"356\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/8.output-of-AND-operator.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/8.output-of-AND-operator-300x153.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>After running the script, two-question prompts will appear asking about your <strong>age<\/strong> and <strong>graduation certificate<\/strong>. If you enter your age of <strong>24<\/strong> and answer <strong>\u2018yes\u2019<\/strong> to the certificate question, the output shows that <strong>you are eligible to apply for this job<\/strong>. However, if you put <strong>24<\/strong> or answer <strong>\u2018no\u2019<\/strong> to the certificate question, the output shows <strong>you are not eligible to apply for this job<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_07_If_Else_Statement_With_Logical_%E2%80%9COR%E2%80%9D_Operator\"><\/span>Example 07: If Else Statement With Logical &#8220;OR&#8221; Operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong>OR<\/strong> operator combines <strong>multiple conditions<\/strong> but it does not need to <strong>satisfy<\/strong> all the conditions like the <strong>AND<\/strong> operator. If <strong>only one<\/strong> condition is <strong>true<\/strong>, the output will be executed. Here, I will explain the same example used in the previous<strong> AND<\/strong> section to let you how the <strong>||<\/strong> operator works under the if else statement. Check the code mentioned below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter your age: &quot;\nread age\necho &quot;Do you have a graduation certificate? (yes\/no): &quot;\nread certificate\nif [ &quot;$age&quot; -ge 23 ] || [ &quot;$certificate&quot; = &quot;yes&quot; ]; then\n\u00a0\u00a0\u00a0 echo &quot;You are eligible to apply for this job.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;You are not eligible to apply for this job.&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>Unlike the <strong>AND<\/strong> operator, the <strong>OR<\/strong> operator does not need to satisfy <strong>both conditions<\/strong>. From the two conditions, if <strong>at least one<\/strong> condition whether age or the certificate is true, the output will show the if block code <strong>&#8220;You are eligible to apply for this job.&#8221; <\/strong>otherwise, it will execute the else block code <strong>&#8220;You are not eligible to apply for this job.&#8221;<\/strong>.<\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24089\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/9.output-of-OR-operator.png\" alt=\"OR operator function within if else\" width=\"700\" height=\"183\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/9.output-of-OR-operator.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/9.output-of-OR-operator-300x78.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p style=\"text-align: justify;\">You can see the bash<strong> OR.sh<\/strong> script\u2019s output in this image. After entering the age of <strong>24<\/strong> and answering <strong>\u2018no\u2019<\/strong> to the 2nd question, it still executes the code that<strong> you are eligible to apply for this job<\/strong>. This is how the <strong>OR<\/strong> operator works with if else statement.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_08_Concatenating_Strings_With_If_Else_in_Bash\"><\/span>Example 08: Concatenating Strings With If Else in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Concatenating <strong>strings <\/strong>is one of the common tasks that everyone should learn to operate the bash script. You are going to have more <strong>control<\/strong> over the concatenation of the strings by adding the <strong>if else <\/strong>condition with it.<\/p>\n<p style=\"text-align: justify;\">This example will explain how to add two strings using the if else statement. Follow the script provided below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter your name: &quot;\nread name\nstring2=&quot;welcome to linuxsimply.com&quot;\nif [ &quot;$name&quot; = &quot;john&quot; ]; then\n\u00a0\u00a0\u00a0 string1=&quot;john&quot;\nelse\n\u00a0\u00a0\u00a0 string1=&quot;$name&quot;\nfi\necho &quot;$string1 $string2&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>If you write the name <strong>john<\/strong>, it will add this <strong>string1<\/strong> with the <code class=\"\" data-line=\"\">string2=&quot;welcome to linuxsimply.com&quot;<\/code>. Else you write another name, that will also be added with<strong> string2.<\/strong><\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24090\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/10.output-of-concatenate.png\" alt=\"concatenating strings using if else\" width=\"535\" height=\"259\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/10.output-of-concatenate.png 535w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/10.output-of-concatenate-300x145.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/p>\n<p style=\"text-align: justify;\">Here, the 1st string is <strong>\u2018name\u2019 <\/strong>and the 2nd string is <strong>\u2018welcome to linuxsimply.com\u2019<\/strong>. If you write the name<strong> john<\/strong>, the output will be <strong>\u2018john welcome to linuxsimply.com\u2019<\/strong> and if put another name, it will add the name with the <strong>2nd string <\/strong>and print the output.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_09_Arithmetic_Operation_With_Variables_Using_If_Else\"><\/span>Example 09: Arithmetic Operation With Variables Using If Else<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><strong>Arithmetic operations<\/strong> mean addition, subtraction, multiplication, and division of variables. These operations can be performed based on different conditions using the<strong> if else<\/strong> statement.<\/p>\n<p style=\"text-align: justify;\">Here, the <strong>addition<\/strong> operation is explained. You can perform other operations as well following a similar procedure. Check the example below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\necho &quot;Enter number1: &quot;\nread num1\necho &quot;Enter number2: &quot;\nread num2\nsum=$((num1 + num2))\nif [ $sum -gt 50 ]; then\n\u00a0\u00a0\u00a0 echo &quot;$sum is greater than 50.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;$sum is less than 50.&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>Here, the <strong>addition<\/strong> operation is performed by adding <strong>number1<\/strong> and <strong>number2<\/strong>. If the sum of the two numbers is <strong>greater<\/strong> than <strong>50<\/strong>, it will execute the <strong>if block<\/strong> code. If it is <strong>false<\/strong>, it will execute the <strong>else block<\/strong> code.<\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24091\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/11.output-of-sum.png\" alt=\"arithmetic sum using if else in bash\" width=\"409\" height=\"386\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/11.output-of-sum.png 409w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/11.output-of-sum-300x283.png 300w\" sizes=\"(max-width: 409px) 100vw, 409px\" \/><\/p>\n<p style=\"text-align: justify;\">Two input variables <strong>30<\/strong> and <strong>40<\/strong> are taken to calculate the <strong>sum<\/strong> and a condition is set using the if else statement. You can notice that the <strong>sum<\/strong> of the variables is <strong>70<\/strong> that\u2019s why it shows the sum is <strong>greater<\/strong> than 50. Then as an input variables <strong>20<\/strong> and <strong>20<\/strong> are added and it shows that the sum is less than 50.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_10_Checking_If_a_File_Exists_With_If_Else\"><\/span>Example 10: Checking If a File Exists With If Else<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can <strong>check<\/strong> whether a file exists in your <strong>Ubuntu<\/strong> or not using the<strong> if else<\/strong> condition. Here, the <strong>-e <\/strong>option is used to check the file&#8217;s existence. You can also <strong>check<\/strong> if a directory exists using the if else statement.<\/p>\n<p style=\"text-align: justify;\">Follow the script provided below to check file existence:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfilepath=&quot;\/home\/mou\/file1.txt&quot;\n# Check if the file exists\nif [ -e &quot;$filepath&quot; ]; then\n\u00a0\u00a0\u00a0 echo &quot;The file1.txt exists.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;The file1.txt does not exist.&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>A file path is defined as <code class=\"\" data-line=\"\">\/home\/mou\/file1.txt<\/code> to check the <strong>file1.txt<\/strong> exists in the <code class=\"\" data-line=\"\">\/home\/mou<\/code> location. Within the if else condition, file existence is checked using the <strong>-e<\/strong> flag.<\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24092\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/12.checking-file-existence.png\" alt=\"checking if a file exists using if else\" width=\"438\" height=\"66\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/12.checking-file-existence.png 438w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/12.checking-file-existence-300x45.png 300w\" sizes=\"(max-width: 438px) 100vw, 438px\" \/><\/p>\n<p>You can see in this image that the <strong>file1.txt<\/strong> exists in the specified location.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_11_Using_If_Else_to_Verify_Password_in_Bash\"><\/span>Example 11: Using If Else to Verify Password in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Verifying <strong>passwords<\/strong> is a common practice to avoid <strong>unauthorized<\/strong> access. Using the <strong>if else<\/strong> condition, you can check if the password is correct or wrong. You will get only <strong>access<\/strong> if the password <strong>matches<\/strong> with the specified password.<\/p>\n<p style=\"text-align: justify;\">To know the process of verifying password using if else statement, follow the below code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Define the valid password\nvalid_pass=&quot;secret&quot;\necho &quot;Enter your password: &quot;\nread entered_pass\n# Check if the entered password is correct\nif [ &quot;$entered_pass&quot; == &quot;$valid_pass&quot; ]; then\n\u00a0\u00a0\u00a0 echo &quot;valid password, access granted.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;invalid password.&quot;\nfi<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p>First of all, you have to define a valid password which is <strong>\u2018secret\u2019<\/strong>. After writing a <strong>password<\/strong> in the prompt, it verifies if the<strong> entered password==valid password<\/strong>. If both password <strong>matches<\/strong>, that is a valid password otherwise the password is <strong>invalid<\/strong>.<\/p>\n<\/div><\/div>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24093\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/13.password-checking.png\" alt=\"checking if a password is correct\" width=\"497\" height=\"257\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/13.password-checking.png 497w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/13.password-checking-300x155.png 300w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/><\/p>\n<p style=\"text-align: justify;\">In this picture, you can notice that when you write the specified password <strong>\u2018secret<\/strong>\u2019, it shows that it is a <strong>valid password<\/strong> and you get access. However, if you write another password <strong>\u2018mou\u2019<\/strong>, it shows that the password is <strong>invalid<\/strong>.<\/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;\">I hope this article helps you understand the <strong>uses<\/strong> of <strong>if else<\/strong> condition. Here, I have shown the <strong>basics<\/strong> of the if else statement including examples and various important <strong>operators<\/strong> used on a regular basis within the if else condition. In addition, <strong>11 examples <\/strong>are explained to let you know the different uses of this conditional statement. Follow each step properly to get an <strong>accurate output<\/strong>. Best wishes.<\/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=\"What_is_the_else_if_statement_in_Bash\"><\/span>What is the else if statement in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In Bash, the <strong>elif<\/strong> <strong>statement<\/strong> is used to check multiple conditions sequentially, acting as a combination of &#8220;else&#8221; and &#8220;if&#8221; in other programming languages. It allows the script to evaluate and execute the block of code associated with the first <strong>true<\/strong> condition encountered. If none of the conditions is <strong>true<\/strong>, the else block is executed.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Is_an_if-else_statement_a_function\"><\/span>Is an if-else statement a function?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No, an if-else statement is not a function. In programming, an if-else statement is a control structure used for decision-making. It allows the execution of different code blocks based on whether a specified condition evaluates to true or false. It is a fundamental part of the flow control in many programming languages, including Bash.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Is_there_Elif_in_bash\"><\/span>Is there Elif in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes definitely, there is an<strong> elif <\/strong>in bash which basically means <strong>else if<\/strong>. It is used for <strong>complex<\/strong> conditional operations.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_does_mean_in_bash\"><\/span>What does @$ mean in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>This special operation passes all the <strong>command line arguments<\/strong> to the <strong>bash script<\/strong> and it must be written within double quotes <strong>\u201c@$\u201d<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_does_mean_in_bash-2\"><\/span>What does == mean in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The == is used to compare strings in bash. For example, <strong>string1==string2 <\/strong>condition will be true if both strings are equal.<br \/>\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"What is the else if statement in Bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"In Bash, the elif statement is used to check multiple conditions sequentially, acting as a combination of \\\"else\\\" and \\\"if\\\" in other programming languages. It allows the script to evaluate and execute the block of code associated with the first true condition encountered. If none of the conditions is true, the else block is executed.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Is an if-else statement a function?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"No, an if-else statement is not a function. In programming, an if-else statement is a control structure used for decision-making. It allows the execution of different code blocks based on whether a specified condition evaluates to true or false. It is a fundamental part of the flow control in many programming languages, including Bash.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Is there Elif in bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Yes definitely, there is an elif in bash which basically means else if. It is used for complex conditional operations.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What does @$ mean in bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"This special operation passes all the command line arguments to the bash script and it must be written within double quotes \u201c@$\u201d.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What does == mean in bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"The == is used to compare strings in bash. For example, string1==string2 condition will be true if both strings are equal.\"\n    }\n  }]\n}\n<\/script><br \/>\n<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\/compare-numbers\/\" target=\"_blank\" rel=\"noopener\">How to Compare Numbers in Bash With If Statement [2 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\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;24071&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;14&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (14 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;If Else in Bash&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            5\/5 - (14 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Controlling the flow of statements execution in the bash program is a fundamental task of decision-making. Therefore, in the bash &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"If Else in Bash\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#more-24071\" aria-label=\"Read more about If Else in Bash\">Read more<\/a><\/p>\n","protected":false},"author":314908,"featured_media":24094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[165],"class_list":["post-24071","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-conditional-statements","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>If Else in Bash - LinuxSimply<\/title>\n<meta name=\"description\" content=\"In this article, I have described about the syntax and uses of the if else in bash. Nested if else statements are also explained here.\" \/>\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\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"If Else in Bash - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"In this article, I have described about the syntax and uses of the if else in bash. Nested if else statements are also explained here.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/\" \/>\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-10-11T08:39:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-08T07:19:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/If-Else-in-Bash.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"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=\"16 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\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/\"},\"author\":{\"name\":\"Mitu Akter Mou\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/54b35370776bb6a79376ea0135412689\"},\"headline\":\"If Else in Bash\",\"datePublished\":\"2023-10-11T08:39:36+00:00\",\"dateModified\":\"2024-02-08T07:19:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/\"},\"wordCount\":3120,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/If-Else-in-Bash.png\",\"keywords\":[\"conditional statements\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/\",\"name\":\"If Else in Bash - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/If-Else-in-Bash.png\",\"datePublished\":\"2023-10-11T08:39:36+00:00\",\"dateModified\":\"2024-02-08T07:19:07+00:00\",\"description\":\"In this article, I have described about the syntax and uses of the if else in bash. Nested if else statements are also explained here.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/If-Else-in-Bash.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/If-Else-in-Bash.png\",\"width\":400,\"height\":400,\"caption\":\"explaining if else statement in bash\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if-else\\\/#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\"}]},{\"@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":"If Else in Bash - LinuxSimply","description":"In this article, I have described about the syntax and uses of the if else in bash. Nested if else statements are also explained here.","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\/","og_locale":"en_US","og_type":"article","og_title":"If Else in Bash - LinuxSimply","og_description":"In this article, I have described about the syntax and uses of the if else in bash. Nested if else statements are also explained here.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/mitalimostakim.mou\/","article_published_time":"2023-10-11T08:39:36+00:00","article_modified_time":"2024-02-08T07:19:07+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/If-Else-in-Bash.png","type":"image\/png"}],"author":"Mitu Akter Mou","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mitu Akter Mou","Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/"},"author":{"name":"Mitu Akter Mou","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/54b35370776bb6a79376ea0135412689"},"headline":"If Else in Bash","datePublished":"2023-10-11T08:39:36+00:00","dateModified":"2024-02-08T07:19:07+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/"},"wordCount":3120,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/If-Else-in-Bash.png","keywords":["conditional statements"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/","name":"If Else in Bash - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/If-Else-in-Bash.png","datePublished":"2023-10-11T08:39:36+00:00","dateModified":"2024-02-08T07:19:07+00:00","description":"In this article, I have described about the syntax and uses of the if else in bash. Nested if else statements are also explained here.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/If-Else-in-Bash.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/10\/If-Else-in-Bash.png","width":400,"height":400,"caption":"explaining if else statement in bash"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/#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"}]},{"@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\/24071","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=24071"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/24071\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/24094"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=24071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=24071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=24071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}