{"id":2787,"date":"2019-11-15T06:00:30","date_gmt":"2019-11-15T06:00:30","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=2787"},"modified":"2019-11-15T06:02:28","modified_gmt":"2019-11-15T06:02:28","slug":"bash-loop-examples","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/bash-loop-examples\/","title":{"rendered":"Bash Loop Examples"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">For i in 1-100 do<\/h2>\n\n\n\n<p>Basically count to 100 and perform an operation each time i increases.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for ((i=1; i<=100;i++))\ndo \n  echo $i\ndone<\/pre>\n\n\n\n<p>for loop 1 liner<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for ((i=1; i<=100;i++)) do echo $i ; done<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">While true (Execute forever)<\/h2>\n\n\n\n<p>Handy if you just want a script to run and repeat the same thing over and over again.  Doesn't stop till you kill it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">while true\ndo\n  echo \"Repeat till infinity\"\n  sleep 1\ndone<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">While command is true<\/h2>\n\n\n\n<p>The following will execute the loop as long as the command in the () returns true.  Once it returns false, it'll stop the loop<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">while (fping incredigeek.com | grep alive); \ndo\n  echo alive\n  sleep 1\ndone<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For i in 1-100 do Basically count to 100 and perform an operation each time i increases. for ((i=1; i<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,792],"tags":[211,430,431,606,405,793],"class_list":["post-2787","post","type-post","status-publish","format-standard","hentry","category-command-line","category-programming","tag-bash","tag-for","tag-loop","tag-programming","tag-scripting","tag-while"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=2787"}],"version-history":[{"count":2,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2787\/revisions"}],"predecessor-version":[{"id":2789,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2787\/revisions\/2789"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=2787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=2787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=2787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}