{"id":19304,"date":"2020-07-10T16:35:01","date_gmt":"2020-07-10T23:35:01","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19304"},"modified":"2023-12-01T03:54:20","modified_gmt":"2023-12-01T11:54:20","slug":"bash-if-else","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/bash-if-else\/","title":{"rendered":"Bash if&#8230;else: A Guide for Beginners"},"content":{"rendered":"\n<p>Conditional statements are an important part of every coding language. They allow you to write code that runs only when certain conditions are met. This means that you can have a program which returns different responses depending on whether certain factors are true.<br><\/p>\n\n\n\n<p>In bash, you can use if statements to make decisions in your code. if statements also come with additional keywords, <code>else<\/code> and <code>elif<\/code>, which give you even more control over how your program executes.<br><\/p>\n\n\n\n<p>In this guide, we\u2019re going to walk through the <code>if...else<\/code> statement in bash. We\u2019ll also create an example program so you can quickly get started using <code>if...else<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Write an if Statement<\/h2>\n\n\n\n<p>Let\u2019s start by focusing on the basics: the if statement. An if statement will evaluate whether a statement is true or false. If the statement is true, the code in the if statement will run.<br><\/p>\n\n\n\n<p>The format of an if statement is like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>if [a condition is met]\nthen\n\t[ do this ]\nfi<\/pre><\/div>\n\n\n\n<p>This code sounds a lot like English. If the condition you specify is met, then the code that comes after the \u201cthen\u201d keyword will be executed. Otherwise, nothing will happen.<br><\/p>\n\n\n\n<p>Notice that in this code the contents of our \u201cthen\u201d block of code are indented. This is important to note because using indents makes your code more readable, thereby reducing the chance that you make an error. Technically, you don\u2019t have to indent your code. However, indenting your code will make your applications more maintainable.<br><\/p>\n\n\n\n<p>Let\u2019s create a program that calculates whether a student has passed a seventh grade math test. Create a file called script.sh and paste in the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>echo -n \"Enter a grade: \"\nread GRADE\nif [[ $GRADE -gt 50 ]]\nthen\n\techo \"The student has passed their test!\"\nfi<\/pre><\/div>\n\n\n\n<p>In this code, we ask the user to enter the numerical grade a student has earned on their test. We then read this grade into our program and use an if statement to check whether that grade is greater than 50. If it is, the message \u201cThe student has passed their test!\u201d is printed to the console. Let\u2019s try out our program by running <code>bash script.sh<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Enter a grade: 70\nThe student has passed their test!<\/pre><\/div>\n\n\n\n<p>In this example, we\u2019ve entered a grade greater than 50. This prompts our \u201cecho\u201d statement to be executed in the \u201cthen\u201d clause of our if statement. Here\u2019s what happens when you enter a value less than 50:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Enter a grade: 50<\/pre><\/div>\n\n\n\n<p>As you can see, no message is printed. That&#8217;s because the condition in our if statement was not met, so the code in our \u201cthen\u201d statement was not executed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Write an Else Statement<\/h2>\n\n\n\n<p>When you\u2019re checking for a condition, it&#8217;s likely that you want something to happen even if your condition is not met. In our example above, we would want a message to appear informing a teacher that a student has failed their test if their grade is below 50.<br><\/p>\n\n\n\n<p>We could do this by adding an <code>else<\/code> statement to our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>echo -n \"Enter a grade: \"\nread GRADE\nif [[ $GRADE -gt 50 ]]\nthen\n\techo \"The student has passed their test!\"\nelse\n\techo \"The student has failed their test!\"\nfi<\/pre><\/div>\n\n\n\n<p>Let\u2019s run our program again and try to insert the value 42:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Enter a grade: 42\nThe student has failed their test!<\/pre><\/div>\n\n\n\n<p>Our script now prints out a message when the user has failed their test. <code>Else<\/code> statements are run if none of the conditions you have specified in an if statement match.<br><\/p>\n\n\n\n<p>In this case, the student\u2019s grade was less than 50, which meant our if statement condition was not met. As a result, the code in our <code>else<\/code> statement was executed.<\/p>\n\n\n\n<p>If we insert a value greater than 50, the code inside our \u201cthen\u201d clause is executed:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Enter a grade: 57\nThe student has passed their test!<\/pre><\/div>\n\n\n\n<p>Using an <code>else<\/code> statement, we can write a two-part conditional. If our condition is met, a block of code will be run; otherwise, another block of code will be run.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Boolean Operations with Bash Scripts<\/h2>\n\n\n\n<p>When you\u2019re writing a bash script, you may only want something to happen if multiple conditions are met, or if one of multiple conditions are met. You can use these operators to check for these cases:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Multiple conditions: &amp;&amp;<\/li>\n\n\n\n<li>One of multiple conditions: ||<\/li>\n<\/ul>\n\n\n\n<p>For instance, you may only want a student to be given a passing grade if their grade is higher than 50 and if their test has been peer-reviewed by another teacher.<br><\/p>\n\n\n\n<p>We could make this happen using the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>echo -n \"Enter a grade: \"\nread GRADE\necho -n \"Has this test been peer reviewed? \"\nread PEER_REVIEW\nif [[ $GRADE -gt 50 &amp;&amp; PEER_REVIEW == \"Y\" ]]\nthen\n\techo \"The student has passed their test!\"\nelse\n\techo \"The student has failed their test!\"\nfi<\/pre><\/div>\n\n\n\n<p>Let\u2019s enter a student\u2019s grade and tell our program that the student\u2019s test has been peer reviewed:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Enter a grade: 62\nHas this test been peer reviewed? Y\nThe student has passed their test!<\/pre><\/div>\n\n\n\n<p>Now, let\u2019s see what happens when we tell our program that a student\u2019s test has not been peer reviewed who has earned the same grade (62):<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Enter a grade: 62\nHas this test been peer reviewed? N\nThe student has failed their test!<\/pre><\/div>\n\n\n\n<p>Because both of our conditions were not met \u2013 GRADE being over 50 and PEER_REVIEW being equal to \u201cY\u201d \u2013 then the contents of our <code>else<\/code> statement were executed.<br><\/p>\n\n\n\n<p>We could substitute the &amp;&amp; for a || symbol if we wanted to check whether one of multiple conditions evaluated to true.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Write an Elif Statement<\/h2>\n\n\n\n<p>While you may only need to check for two conditions, there are plenty of cases where you may want to evaluate multiple different statements. That\u2019s where the <code>elif<\/code> statement comes in handy.<br><\/p>\n\n\n\n<p>Let\u2019s make our grade calculator a little more advanced. Suppose we want to calculate a student&#8217;s letter grade based on their numerical grade. We want to assign the following letters based on a student\u2019s grade:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>86 or above is considered an A<\/li>\n\n\n\n<li>71 to 85 is considered a B<\/li>\n\n\n\n<li>61 to 70 is considered a C<\/li>\n\n\n\n<li>51 to 60 is considered a D<\/li>\n\n\n\n<li>Below 50 is considered an F<\/li>\n<\/ul>\n\n\n\n<p>For this code, we are going to need to use an if, <code>elif<\/code> and <code>else<\/code> statements.<br><\/p>\n\n\n\n<p>Open up the script.sh file from earlier and change the if statement to use the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>echo -n \"Enter a grade: \"\nread GRADE\nif [[ $GRADE -ge 86 ]];\nthen\n \techo \"The student has earned an A grade.\"\nelif [[ $GRADE -ge 71 ]]; then\n\techo \"The student has earned a B grade.\"\nelif [[ $GRADE -ge 61 ]]; then\n\techo \"The student has earned a C grade.\"\nelif [[ $GRADE -ge 51 ]]; then\n\techo \"The student has earned a D grade.\"\nelse\n\techo \"The student has earned an F grade.\"\nfi<\/pre><\/div>\n\n\n\n<p>There\u2019s a lot going on in our code, so let\u2019s break it down.<br><\/p>\n\n\n\n<p>First, we use an if statement to check if a student\u2019s grade is greater than 86. If it is, the student has earned an A grade. If this statement evaluates to false, our program will check whether the student\u2019s grade is greater than 71 using the -ge operator.<br><\/p>\n\n\n\n<p>If this does not evaluate to true, our program will keep going through our grade boundary checker.<br><\/p>\n\n\n\n<p>If a student\u2019s grade does not meet any of our if or <code>elif<\/code> conditions, the contents of the <code>else<\/code> block of code are executed. This returns an F grade for the student.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Nested if Statements<\/h2>\n\n\n\n<p>There\u2019s no limit to how many if statements you can have inside your bash script. What\u2019s more, if statements can be contained within themselves. This means that you can check for a condition only when another condition is met.<br><\/p>\n\n\n\n<p>Suppose we want to check whether a student\u2019s grade is even or odd, but only if they passed their test. We could do so using this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>echo -n \"Enter a grade: \"\nread GRADE\nif [[ $GRADE -gt 50 ]]\nthen\n\techo \"The student has passed their test!\"\n\tif (( $GRADE % 2 == 0 ))\n\tthen\n\t\techo \"This grade is an even number.\"\n\telse\n\t\techo \"This grade is an odd number.\"\n\tfi\nfi<\/pre><\/div>\n\n\n\n<p>In this code, our program first checks to see whether a student\u2019s grade is greater than 50. If it is, a message is printed to the console. Next, our program checks whether a student\u2019s grade is an even number. We do this using the following line of code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>(( $GRADE % 2 == 0 ))<\/pre><\/div>\n\n\n\n<p>This code uses the modulo operator (%) to check whether our number is even or odd. If it is even, a message stating the number is even is printed to the console; otherwise, a message stating that the number is odd is printed to the console.<\/p>\n\n\n\n<p>Let\u2019s run our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Enter a grade: 95\nThe student has passed their test!\nThis grade is an odd number.<\/pre><\/div>\n\n\n\n<p>When a student\u2019s grade is greater than 50, our program calculates whether their grade is an odd or an even number. Let\u2019s see what happens if we insert a grade lower than 50:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Enter a grade: 49<\/pre><\/div>\n\n\n\n<p>Our code doesn\u2019t return anything because the condition in our if statement is not met.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The if, if&#8230;else, and elif keywords allow you to control the flow of your code. Using an if statement, you can check whether a specific condition is met. Elif statements allow you to check for multiple conditions. Else statements execute only if no other condition is met.<br><\/p>\n\n\n\n<p>Here are a few challenges for you if you are interested in building your knowledge of if statements:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create an application that calculates the price of a ticket to a theme park based on the age of its customers<\/li>\n\n\n\n<li>Create an application that checks whether a file is executable<\/li>\n\n\n\n<li>Create an application that figures out which of two files was updated most recently<\/li>\n<\/ul>\n\n\n\n<p>For reference, you can check out the devhints.io Bash scripting guide. This provides a list of possible options for use with a conditional statement.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to start using bash if&#8230;else statements like a scripting expert!<\/p>\n","protected":false},"excerpt":{"rendered":"Conditional statements are an important part of every coding language. They allow you to write code that runs only when certain conditions are met. This means that you can have a program which returns different responses depending on whether certain factors are true. In bash, you can use if statements to make decisions in your&hellip;","protected":false},"author":240,"featured_media":19305,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[18070],"tags":[],"class_list":{"0":"post-19304","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-software-engineering-skills"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Coding","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Bash if...else: A Guide for Beginners %<\/title>\n<meta name=\"description\" content=\"The if else statement allows you to control the flow of your bash programs. On Career Karma, learn how to use the if, else, and elif keywords in bash.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/bash-if-else\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bash if...else: A Guide for Beginners\" \/>\n<meta property=\"og:description\" content=\"The if else statement allows you to control the flow of your bash programs. On Career Karma, learn how to use the if, else, and elif keywords in bash.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/bash-if-else\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-10T23:35:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:54:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Bash if&#8230;else: A Guide for Beginners\",\"datePublished\":\"2020-07-10T23:35:01+00:00\",\"dateModified\":\"2023-12-01T11:54:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/\"},\"wordCount\":1388,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg\",\"articleSection\":[\"Software Engineering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/bash-if-else\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/\",\"name\":\"Bash if...else: A Guide for Beginners %\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg\",\"datePublished\":\"2020-07-10T23:35:01+00:00\",\"dateModified\":\"2023-12-01T11:54:20+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The if else statement allows you to control the flow of your bash programs. On Career Karma, learn how to use the if, else, and elif keywords in bash.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/bash-if-else\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-if-else\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Engineering\",\"item\":\"https:\/\/careerkarma.com\/blog\/software-engineering-skills\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash if&#8230;else: A Guide for Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Bash if...else: A Guide for Beginners %","description":"The if else statement allows you to control the flow of your bash programs. On Career Karma, learn how to use the if, else, and elif keywords in bash.","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:\/\/careerkarma.com\/blog\/bash-if-else\/","og_locale":"en_US","og_type":"article","og_title":"Bash if...else: A Guide for Beginners","og_description":"The if else statement allows you to control the flow of your bash programs. On Career Karma, learn how to use the if, else, and elif keywords in bash.","og_url":"https:\/\/careerkarma.com\/blog\/bash-if-else\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-10T23:35:01+00:00","article_modified_time":"2023-12-01T11:54:20+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Bash if&#8230;else: A Guide for Beginners","datePublished":"2020-07-10T23:35:01+00:00","dateModified":"2023-12-01T11:54:20+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/"},"wordCount":1388,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg","articleSection":["Software Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/bash-if-else\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/","url":"https:\/\/careerkarma.com\/blog\/bash-if-else\/","name":"Bash if...else: A Guide for Beginners %","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg","datePublished":"2020-07-10T23:35:01+00:00","dateModified":"2023-12-01T11:54:20+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The if else statement allows you to control the flow of your bash programs. On Career Karma, learn how to use the if, else, and elif keywords in bash.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/bash-if-else\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/sigmund-AxAPuIRWHGk-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/bash-if-else\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Software Engineering","item":"https:\/\/careerkarma.com\/blog\/software-engineering-skills\/"},{"@type":"ListItem","position":3,"name":"Bash if&#8230;else: A Guide for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=19304"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19304\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/19305"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}