{"id":19098,"date":"2020-07-06T21:02:45","date_gmt":"2020-07-07T04:02:45","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19098"},"modified":"2023-12-01T03:39:05","modified_gmt":"2023-12-01T11:39:05","slug":"bash-while-loop","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/","title":{"rendered":"Bash while Loop: A Beginner\u2019s Guide"},"content":{"rendered":"\n<p>While loops. While loops. While loops. I could have written a bash program to write those sentences instead of writing <code>while loops<\/code> three times over myself.<br><\/p>\n\n\n\n<p>Loops are a foundational component of most programming languages. They allow you to automate and repeat similar tasks so that you can reduce repetition in your code.<br><\/p>\n\n\n\n<p>In this guide, we\u2019re going to talk about the while loop, how it works, and how you can use it in your bash scripts. We\u2019ll walk through an example of a while loop so you can get started quickly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bash while Loop<\/h2>\n\n\n\n<p><code>While loops<\/code> are sort of like a repeating conditional statement. They run a block of code only when a condition evaluates to true. Otherwise, the loop does not execute.<br><\/p>\n\n\n\n<p>While loops are conditionally based. This means that, unlike for loops, you don\u2019t need to know how many times a block of code should repeat before the loop starts.<br><\/p>\n\n\n\n<p>This is useful because it means you can keep your loop going until you change a variable. This may be more practical than having a loop that runs a specific amount of times in many scenarios.<br><\/p>\n\n\n\n<p>Examples where a while loop could be useful include where you want a user to guess a number until they get it right or try to enter their password until they enter the correct one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Write a while Loop<\/h2>\n\n\n\n<p>In bash, while loops are written like this:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>while [condition]\ndo\n\t[run commands]\ndone\n<\/pre><\/div>\n\n\n\n<p>The syntax for the while loop reinforced a crucial part of bash\u2019s syntax: it\u2019s easy to read. Before we continue, take a moment to read the above syntax over in your head. It\u2019s simple!<br><\/p>\n\n\n\n<p>The <code>run commands<\/code> will be executed until the condition we have specified is no longer true.<br><\/p>\n\n\n\n<p>Let\u2019s create a password-checking program to show how this works. In this program, we\u2019re going to ask a user to insert their username and password. If their password is correct, the loop will print a message informing the user and then will stop; if the password is not correct, our loop will keep going.<br><\/p>\n\n\n\n<p>Create a file called password.sh and paste in the following line of code:<br><\/p>\n\n\n\n<p><code>found=false<br><\/code><\/p>\n\n\n\n<p>We\u2019ve just declared a variable. This variable will track whether the user has inserted the correct password. We\u2019re setting its initial value to <code>false<\/code> so that our while loop runs at least once.<br><\/p>\n\n\n\n<p>Next, we\u2019re going to add in this block of code to create our while loop:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>while [[ $found == false ]]\ndo\n\techo \"Insert your password.\"\n\tread password\ndone\n<\/pre><\/div>\n\n\n\n<p>This code will ask our user for their password until the value of \u201cfound\u201d is not equal to false. Now our user can insert a password, but we haven\u2019t yet checked to see if this password is correct. Paste the following code directly after the <code>read password<\/code> line from earlier:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>if [[ $password == \"test\" ]];\n\tthen\n\t\techo \"You've entered the correct password.\"\n\t\tfound=true\n\telse\n\t\techo \"Your password is incorrect.\"\n\tfi\n<\/pre><\/div>\n\n\n\n<p>We\u2019ve declared a while loop which will keep running until the variable <code>found<\/code> is no longer equal to false. When this loop executes, our user will be asked to insert their password, and the value the user enters is saved as the variable \u201cpassword.\u201d<br><\/p>\n\n\n\n<p>Once a user has entered a password, an <code>if<\/code> statement runs to check whether they\u2019ve entered the correct password, which is test in this example. When a user inserts the correct password, \u201c<code>You\u2019ve entered the correct password.<\/code>\u201d is printed to the console. Our found variable is then set to true, which means that our while loop will not run again.<br><\/p>\n\n\n\n<p>Here\u2019s what happens when we insert the correct password:<br><\/p>\n\n\n\n<p>Insert your password.<\/p>\n\n\n\n<p>test<\/p>\n\n\n\n<p>You&#8217;ve entered the correct password.<br><\/p>\n\n\n\n<p>When a user inserts the wrong password, the <code>else<\/code> statement in our <code>if<\/code> statement will run. This will prompt the message \u201cYour password is incorrect.\u201d to the user. Then, our while loop will run again, until the user inserts the correct password:<br><\/p>\n\n\n\n<p>Insert your password.<\/p>\n\n\n\n<p>test123<\/p>\n\n\n\n<p>Your password is incorrect.<\/p>\n\n\n\n<p>Insert your password.<\/p>\n\n\n\n<p>test<\/p>\n\n\n\n<p>You\u2019ve entered the correct password.<br><\/p>\n\n\n\n<p>At first, we entered an incorrect password. This means that our program executes the <code>else<\/code> statement in our <code>if<\/code> statement, so we\u2019re notified that our password is incorrect. On our next attempt, we successfully insert our password. This prompts us with a message informing us of such, then our program stops executing.<br><\/p>\n\n\n\n<p>When you\u2019re working with while loops, you may want to break out of them and halt your program. You can do this by pressing CTRL + C or Cmd + C, which will halt execution of your bash script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Read a File Line By Line<\/h2>\n\n\n\n<p>There\u2019s a lot you can do with a while loop \u2013 you could build a guessing game, for example \u2013 but one of the most common things you\u2019ll find people do with a while loop is read a file line by line.<br><\/p>\n\n\n\n<p>While loops are perfect for this case because they\u2019ll run until a certain condition is met. That means you don\u2019t need to know \u2013 or find out \u2013 how many lines are in a file. You can tell your program to print out each line while there are still lines to read.<br><\/p>\n\n\n\n<p>Let\u2019s say that we want to print out the file <code>\/etc\/hosts<\/code> on our computer. Create a file called <code>read_file.sh<\/code> and paste in this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>file=\/etc\/hosts\nwhile read -r line; do\n\techo $line\ndone &lt; $file\n<\/pre><\/div>\n\n\n\n<p>This example is slightly different from our last one. Instead of passing a condition with our while loop, we\u2019re using input redirection (&lt;<code> $file<\/code>). This is used to tell our program from which file it should read. When the last file of our program is read, our program will halt execution.<br><\/p>\n\n\n\n<p>Our code returns the contents of the standard \/etc\/hosts file, which are:<br><\/p>\n\n\n\n<p>127.0.0.1 localhost<\/p>\n\n\n\n<p>255.255.255.255 broadcasthost<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using Break and Continue Statements<\/h2>\n\n\n\n<p>While loops can be used alongside break and continue statements. These statements give you more control over the flow of your code:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A break statement terminates the current loop.<\/li>\n\n\n\n<li>A continue statement exits the current iteration of a loop and allows the loop to continue iterating.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Break Statements<\/h3>\n\n\n\n<p>Let\u2019s beef up our password evaluation program from earlier. In our last example, our user could try to insert their password an infinite number of times. Let\u2019s impose a restriction which states that users cannot have any more than three attempts:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>tries=0\nfound=false\nwhile [[ $found == false ]]\ndo\n\tif [[ tries -eq 3 ]];\n\tthen\n\t\techo \"You have run out of tries.\"\n\t\tbreak\n\tfi\n\techo \"Insert your password.\"\n\tread password\n\tif [[ $password == \"test\" ]];\n\tthen\n    \techo \"You've entered the correct password.\"\n    \tfound=true\n\telse\n\t\t((tries++))\n    \t\techo \"Your password is incorrect\"\n\tfi\ndone\n<\/pre><\/div>\n\n\n\n<p>We\u2019ve added a few pieces of code to our while loop. We\u2019ve first declared a variable called \u201ctries\u201d which tracks how many times our user has tried to insert their password.<br><\/p>\n\n\n\n<p>Within our <code>while<\/code> loop we\u2019ve added another <code>if<\/code> statement. This checks if a user has tried to enter their password three times. If this is the case, the program will keep running. If a user has tried to enter their password three times, this <code>if<\/code> statement will execute.<br><\/p>\n\n\n\n<p>The message <code>You have run out of tries.<\/code> will be printed to the console if the statement executes. Then, our loop will break, which means our program will stop running.<br><\/p>\n\n\n\n<p>We\u2019ve also added an increment counter <code>( ((tries++)) )<\/code> to the <code>if.<\/code> statement that checks our user\u2019s password. This increases the value of <code>tries<\/code> by 1 every time a user incorrectly types in their password.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Continue Statement<\/h3>\n\n\n\n<p>The continue statement stops one iteration of a <code>while<\/code> loop and goes onto the next one. To illustrate this, consider the following example:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>count=0\nwhile [[ $count -lt 3 ]]\ndo\n\t((count++))\n\tif [[ $count -eq 1 ]];\n\tthen\n\t\tcontinue\n\tfi\n\techo \"Count: $count\"\ndone\n<\/pre><\/div>\n\n\n\n<p>In this program, we\u2019ve created a loop which executes while the value of <code>count<\/code> is less than 3. Each time the loop executes, the value of <code>count<\/code> is increased by one.<br><\/p>\n\n\n\n<p>Our program then checks if count is equal to 1. If this is the case, the current iteration of the loop will halt and the next one will begin. Otherwise, the loop will keep running and will print <code>Count: <\/code>, followed by the value of \u201ccount\u201d, to the console.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>While loops allow you to execute the same block of code multiple times. Unlike for loops, you don\u2019t need to instruct a while loop on how many times it should run. A while loop will run until a condition is no longer true.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to start writing while loops in your bash scripts like a pro!<br><\/p>\n","protected":false},"excerpt":{"rendered":"While loops. While loops. While loops. I could have written a bash program to write those sentences instead of writing while loops three times over myself. Loops are a foundational component of most programming languages. They allow you to automate and repeat similar tasks so that you can reduce repetition in your code. In this&hellip;","protected":false},"author":240,"featured_media":2604,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[18070],"tags":[],"class_list":{"0":"post-19098","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 while Loop: A Beginner\u2019s Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"While loops run a block of code only when a statement evaluates to true. On Career Karma, learn how to write your own while loops 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-while-loop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bash while Loop: A Beginner\u2019s Guide\" \/>\n<meta property=\"og:description\" content=\"While loops run a block of code only when a statement evaluates to true. On Career Karma, learn how to write your own while loops in bash.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/\" \/>\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-07T04:02:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:39:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\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-while-loop\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Bash while Loop: A Beginner\u2019s Guide\",\"datePublished\":\"2020-07-07T04:02:45+00:00\",\"dateModified\":\"2023-12-01T11:39:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/\"},\"wordCount\":1309,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg\",\"articleSection\":[\"Software Engineering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/\",\"name\":\"Bash while Loop: A Beginner\u2019s Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg\",\"datePublished\":\"2020-07-07T04:02:45+00:00\",\"dateModified\":\"2023-12-01T11:39:05+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"While loops run a block of code only when a statement evaluates to true. On Career Karma, learn how to write your own while loops in bash.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg\",\"width\":1200,\"height\":800},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#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 while Loop: A Beginner\u2019s Guide\"}]},{\"@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 while Loop: A Beginner\u2019s Guide | Career Karma","description":"While loops run a block of code only when a statement evaluates to true. On Career Karma, learn how to write your own while loops 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-while-loop\/","og_locale":"en_US","og_type":"article","og_title":"Bash while Loop: A Beginner\u2019s Guide","og_description":"While loops run a block of code only when a statement evaluates to true. On Career Karma, learn how to write your own while loops in bash.","og_url":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-07T04:02:45+00:00","article_modified_time":"2023-12-01T11:39:05+00:00","og_image":[{"width":1200,"height":800,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.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-while-loop\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Bash while Loop: A Beginner\u2019s Guide","datePublished":"2020-07-07T04:02:45+00:00","dateModified":"2023-12-01T11:39:05+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/"},"wordCount":1309,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg","articleSection":["Software Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/bash-while-loop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/","url":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/","name":"Bash while Loop: A Beginner\u2019s Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg","datePublished":"2020-07-07T04:02:45+00:00","dateModified":"2023-12-01T11:39:05+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"While loops run a block of code only when a statement evaluates to true. On Career Karma, learn how to write your own while loops in bash.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/bash-while-loop\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/luca-bravo-217276-unsplash-1.jpg","width":1200,"height":800},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/bash-while-loop\/#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 while Loop: A Beginner\u2019s Guide"}]},{"@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\/19098","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=19098"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19098\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/2604"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}