{"data":{"markdownRemark":{"html":"<p>Nested <code class=\"language-text\">if</code> statements (that is, if statements within if statements) are cool and all, and will usually do the job nicely, but if your list of <code class=\"language-text\">if</code>s for all possible outcomes gets bigger and bigger, then the code become unreadable quite quickly... case statements to the rescue!</p>\n<p><code class=\"language-text\">case</code> is an incredibly useful tool in your scripting arsenal, but so many sysadmins and bash developers don't use it to its full potential. Lets break it down here, and walk through a few of its uses to clear up some confusion,</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token keyword\">case</span> EXPRESSION <span class=\"token keyword\">in</span>\n    CASE1<span class=\"token punctuation\">)</span>\n        COMMAND1\n        COMMAND2\n        <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n    CASE2<span class=\"token punctuation\">)</span>\n        COMMAND3\n        <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n    CASE3<span class=\"token punctuation\">)</span>\n        COMMAND4\n        COMMAND5\n        COMMAND6\n        <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n    CASE4<span class=\"token operator\">|</span>CASE5<span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">exit</span>\n        <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n    *<span class=\"token punctuation\">)</span>\n        OTHER COMMANDS HERE\n        <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\nesac</code></pre></div>\n<h2 id=\"what-does-all-that-mean\"><a href=\"#what-does-all-that-mean\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What does all that mean?</h2>\n<p>Lets break it down...  (and dont worry if you dont get it at first look, all will become clearer further down)</p>\n<ul>\n<li>\n<p><code class=\"language-text\">case EXPRESSION in</code> </p>\n<ul>\n<li><code class=\"language-text\">case</code> is the command we are using ( the one we are learning about right now )</li>\n<li><code class=\"language-text\">EXPRESSION</code> is the thing we want to test, it could be a string, a number, an input (eg: $1)</li>\n<li><code class=\"language-text\">in</code> is a keyword for the case command to check if EXPRESSION is \"in\" the below list</li>\n</ul>\n</li>\n<li>\n<p><code class=\"language-text\">CASE1)</code></p>\n<ul>\n<li>the first \"case\" that our expression could be, if <code class=\"language-text\">EXPRESSION</code> matches <code class=\"language-text\">CASE1</code> it will execute <code class=\"language-text\">COMMAND1</code> and <code class=\"language-text\">COMMAND2</code> below</li>\n</ul>\n</li>\n<li>\n<p><code class=\"language-text\">;;</code> this symbol will tell <code class=\"language-text\">case</code> that it has finished executing the correct <code class=\"language-text\">COMMANDS</code> for this <code class=\"language-text\">CASE</code> and will now exit the <code class=\"language-text\">case</code> statement altogether. It's a very common mistake to forget to put <code class=\"language-text\">;;</code> at the end of each <code class=\"language-text\">CASE</code> and can case some seriously unwanted code to execute so remember to put it there!</p>\n</li>\n</ul>\n<h3 id=\"code-classlanguage-textexpressioncode-didnt-match-code-classlanguage-textcase1code-what-now\"><a href=\"#code-classlanguage-textexpressioncode-didnt-match-code-classlanguage-textcase1code-what-now\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code class=\"language-text\">EXPRESSION</code> didn't match <code class=\"language-text\">CASE1</code>, what now?</h3>\n<p>well <code class=\"language-text\">case</code> will continue down the list of cases... so, onto the next <code class=\"language-text\">CASE!</code></p>\n<ul>\n<li>\n<p><code class=\"language-text\">CASE2</code>)</p>\n<ul>\n<li>Because no match was made for <code class=\"language-text\">CASE1</code> then <code class=\"language-text\">case</code> will <strong><em>not</em></strong> execute any of the commands inside the <code class=\"language-text\">CASE1</code> block, and will continue down the list to <code class=\"language-text\">CASE2</code> looking for another match...</li>\n<li>If it finds a match in <code class=\"language-text\">CASE2</code> then it will execute <code class=\"language-text\">COMMAND3</code> inside that block...</li>\n<li>if <em>still</em> no match is found, <code class=\"language-text\">case</code> will continue looking further and further down the list until it finds a match</li>\n</ul>\n</li>\n</ul>\n<h3 id=\"what-if-it-never-finds-a-match\"><a href=\"#what-if-it-never-finds-a-match\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What if it never finds a match?</h3>\n<p>Great question!  thats where this line does its job...</p>\n<ul>\n<li>\n<p><code class=\"language-text\">*)\n    OTHER COMMANDS HERE\n    ;;</code></p>\n<ul>\n<li>The <code class=\"language-text\">*</code> symbol here is considered as a \"catch-all\", that is to say if no <code class=\"language-text\">CASE</code> matched our <code class=\"language-text\">EXPRESSION</code> then <code class=\"language-text\">*</code> will catch it, and any commands within the <code class=\"language-text\">*</code> block will execute. So we know every possible input will be caught somehow. <code class=\"language-text\">*</code> can be used to catch invalid input and return an error message to the user to wise-up ... (see below)</li>\n</ul>\n</li>\n</ul>\n<p>and ....</p>\n<ul>\n<li><code class=\"language-text\">esac</code> ends the <code class=\"language-text\">case</code> statement, (its <code class=\"language-text\">case</code> backwards, geddit?), again its a common gotcha to forget to end with <code class=\"language-text\">esac</code> and it <strong>will</strong> make you crazy trying to figure out whats going wrong, so don't forget it!</li>\n</ul>\n<h3 id=\"ok-got-it-still-completely-confused\"><a href=\"#ok-got-it-still-completely-confused\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Ok, got it.... still completely confused!</h3>\n<p>No problem my furry little friend..  a picture is worth a 1000 words... so lets look at 3000 words to see some examples of what we learned here...</p>\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/example1-b230ccd3172e109cc14eaeb552534d74-20333.jpg\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 710px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 38.84093711467324%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAIABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAEF/8QAFgEBAQEAAAAAAAAAAAAAAAAAAwAB/9oADAMBAAIQAxAAAAHHghBt/8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQABBQJ//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQAGPwJ//8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQABPyF//9oADAMBAAIAAwAAABAMH//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8QP//EABkQAQACAwAAAAAAAAAAAAAAAAEAEBFRof/aAAgBAQABPxBSZd9r/9k='); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"example1\"\n        title=\"\"\n        src=\"/static/example1-b230ccd3172e109cc14eaeb552534d74-8b432.jpg\"\n        srcset=\"/static/example1-b230ccd3172e109cc14eaeb552534d74-81942.jpg 178w,\n/static/example1-b230ccd3172e109cc14eaeb552534d74-60db8.jpg 355w,\n/static/example1-b230ccd3172e109cc14eaeb552534d74-8b432.jpg 710w,\n/static/example1-b230ccd3172e109cc14eaeb552534d74-20333.jpg 811w\"\n        sizes=\"(max-width: 710px) 100vw, 710px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n<h4 id=\"quick-explanation\"><a href=\"#quick-explanation\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Quick explanation...</h4>\n<ul>\n<li>on Line 5, im using the <code class=\"language-text\">read</code> command (another command for another tutorial TODO(make <code class=\"language-text\">read</code> tutorial)  to get the user to input a number from 0 to 9, and save that input into a variable called \"user_input\"</li>\n<li>on Line 7 my <code class=\"language-text\">case</code> statement begins, and <code class=\"language-text\">user_input</code> is my <code class=\"language-text\">EXPRESSION</code> I am checking the value of.</li>\n<li>\n<p>if <code class=\"language-text\">user_input</code> is either 1  (this symbol --> |   means \"or\" here) or 3 or 5  or 7 or 9 then execute the code in this block...</p>\n<ul>\n<li>echo to the screen our distaste of odd numbers.</li>\n<li>then <code class=\"language-text\">;;</code> will exit the <code class=\"language-text\">case</code> command altogether, no further checks will be made on <code class=\"language-text\">user_input</code></li>\n</ul>\n</li>\n<li>if no odd number was entered then the first <code class=\"language-text\">CASE</code> (odd numbers) will be skipped and <code class=\"language-text\">case</code> will continue down the list...</li>\n<li>\n<p>The next block is checking if <code class=\"language-text\">user_input</code> is 2 or 4 or 6 or 8.  If it is on of these, the code below will execute,</p>\n<ul>\n<li>echo to the screen our love of even numbers</li>\n<li><code class=\"language-text\">;;</code> will exit the case command altogether</li>\n</ul>\n</li>\n<li>The same logic continues that if <code class=\"language-text\">user_input</code> is 0 (zero) then the code below that <code class=\"language-text\">CASE</code> below is executed (no strong feelings about zero)</li>\n<li>if the user entered the number \"38489235\" or \"10\" or \"eggs\" then it will be caught by <code class=\"language-text\">*</code> and the user will be informed they made a mistake with their input and the <code class=\"language-text\">case</code> statement will end, the user could then taken back to the beginning where they again have the option to enter a valid number.</li>\n</ul>\n<h4 id=\"choices-within-choices-options-within-options\"><a href=\"#choices-within-choices-options-within-options\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Choices within choices, Options within options....</h4>\n<p>The code here is basically the same as above, just with two minor changes...\nwe can also embed <code class=\"language-text\">if</code> statements within <code class=\"language-text\">case</code> statements, to add more functionality to our checks and outputs...</p>\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/example2-a158958f21eb4b92281e62018636a99d-1b48b.jpg\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 710px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 48.07467911318554%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAKABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAEF/8QAFgEBAQEAAAAAAAAAAAAAAAAAAwAB/9oADAMBAAIQAxAAAAHHghQbf//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAQUCX//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8BP//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEABj8CX//EABUQAQEAAAAAAAAAAAAAAAAAAAEg/9oACAEBAAE/IWv/2gAMAwEAAgADAAAAEI/f/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPxA//8QAFREBAQAAAAAAAAAAAAAAAAAAARD/2gAIAQIBAT8QJ//EABsQAAIBBQAAAAAAAAAAAAAAAAEREABRYYGR/9oACAEBAAE/EEWs0zc9gmf/2Q=='); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"example2\"\n        title=\"\"\n        src=\"/static/example2-a158958f21eb4b92281e62018636a99d-8b432.jpg\"\n        srcset=\"/static/example2-a158958f21eb4b92281e62018636a99d-81942.jpg 178w,\n/static/example2-a158958f21eb4b92281e62018636a99d-60db8.jpg 355w,\n/static/example2-a158958f21eb4b92281e62018636a99d-8b432.jpg 710w,\n/static/example2-a158958f21eb4b92281e62018636a99d-1b48b.jpg 857w\"\n        sizes=\"(max-width: 710px) 100vw, 710px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n<ul>\n<li>\n<p>Above we can see if the user enters for <code class=\"language-text\">user_input</code> the value of \"4\" then the following code will execute</p>\n<ul>\n<li><code class=\"language-text\">echo &quot;you chose an even number, NICE!&quot;</code></li>\n<li>then there will be a check to see if <code class=\"language-text\">user_input</code> is equal to 2. Obviously 4 is not equal to 2, so this will not be true, and the <code class=\"language-text\">if</code> statement ends, as does the <code class=\"language-text\">case</code> statement, and we carry on with our lives...</li>\n</ul>\n</li>\n<li>\n<p>However if the user does enter \"2\" as <code class=\"language-text\">user_input</code> then this is the output of our script....\n\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/example3-3cbb5e80cd8564ee5090696a83ddf0a4-de4ae.jpg\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 710px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 11.350737797956867%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAACABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAIF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3aAD/8QAFRABAQAAAAAAAAAAAAAAAAAAARD/2gAIAQEAAQUCL//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8BP//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8hX//aAAwDAQACAAMAAAAQ88//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/ED//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/ED//xAAXEAEBAQEAAAAAAAAAAAAAAAABABFR/9oACAEBAAE/EAalhyw5f//Z'); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"example3\"\n        title=\"\"\n        src=\"/static/example3-3cbb5e80cd8564ee5090696a83ddf0a4-8b432.jpg\"\n        srcset=\"/static/example3-3cbb5e80cd8564ee5090696a83ddf0a4-81942.jpg 178w,\n/static/example3-3cbb5e80cd8564ee5090696a83ddf0a4-60db8.jpg 355w,\n/static/example3-3cbb5e80cd8564ee5090696a83ddf0a4-8b432.jpg 710w,\n/static/example3-3cbb5e80cd8564ee5090696a83ddf0a4-de4ae.jpg 881w\"\n        sizes=\"(max-width: 710px) 100vw, 710px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n</li>\n</ul>\n<p>beautiful...</p>\n<blockquote>\n<p>👍 Try to go ahead now and think how you can use <code class=\"language-text\">case</code> statements inside <code class=\"language-text\">case</code> statements, to really fine-tune your <code class=\"language-text\">EXPRESSION</code> matching</p>\n</blockquote>\n<h4 id=\"finally-a-practical-example\"><a href=\"#finally-a-practical-example\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Finally a practical example,</h4>\n<p>Have a look at this and think how it could help you automate some of your daily work as a sysadmin,\nall I will explain is that \"$1\" is a bash standard shortcut for the \"first value given after the script name...\" so in this example..</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">my_terminal_prompt:<span class=\"token operator\">></span> ./my_awesome_script.sh sean will <span class=\"token function\">help</span> you</code></pre></div>\n<ul>\n<li>\"my_awesome_script.sh\"  = \"$0\" (the actual script)</li>\n<li>\"sean\" = \"$1\" (the first parameter)</li>\n<li>\"will\" = \"$2\" (the second parameter etc etc)</li>\n<li>\"help\" = \"$3\"</li>\n<li>\"you\" = \"$4\"</li>\n</ul>\n<p>and in this example</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">systemctl status ntp</code></pre></div>\n<ul>\n<li>status = $1</li>\n</ul>\n<p>so, keeping that in mind, have a look below...</p>\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/example4-a0502c4c25d7d5ba6476bf83b88267cc-d39d4.jpg\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 710px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 46.24724061810155%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAJABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAEF/8QAFQEBAQAAAAAAAAAAAAAAAAAAAAP/2gAMAwEAAhADEAAAAceRSYH/xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAEFAl//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAY/Al//xAAWEAEBAQAAAAAAAAAAAAAAAAAQAUH/2gAIAQEAAT8hxr//2gAMAwEAAgADAAAAEKsv/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPxA//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPxA//8QAGBAAAwEBAAAAAAAAAAAAAAAAARAxESH/2gAIAQEAAT8QGWeun//Z'); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"example4\"\n        title=\"\"\n        src=\"/static/example4-a0502c4c25d7d5ba6476bf83b88267cc-8b432.jpg\"\n        srcset=\"/static/example4-a0502c4c25d7d5ba6476bf83b88267cc-81942.jpg 178w,\n/static/example4-a0502c4c25d7d5ba6476bf83b88267cc-60db8.jpg 355w,\n/static/example4-a0502c4c25d7d5ba6476bf83b88267cc-8b432.jpg 710w,\n/static/example4-a0502c4c25d7d5ba6476bf83b88267cc-d39d4.jpg 906w\"\n        sizes=\"(max-width: 710px) 100vw, 710px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n<p>Now go and play my (script) kiddies! Have a great day!</p>\n<p>If Sean Helped You today, feel free to share this post or connect with us soon, available via <a href=\"mailto:seanwillhelpyou@gmail.com\">gmail</a>, <a href=\"https://app.slack.com/client/TLMMVFQ1X/CLVTNC1MM\">slack</a> or <a href=\"https://github.com/RH-sdavey/sean-will-help-you\">github</a>.\nThanks for reading!</p>","timeToRead":6,"excerpt":"Nested   statements (that is, if statements within if statements) are cool and all, and will usually do the job nicely, but if your list of…","frontmatter":{"title":"How to use 'case' statements in Bash scripting","cover":"https://picsum.photos/id/535/2500/1000","date":"2019-09-04","category":"Sysadmin","tags":["Sysadmin","Easy","Bash"],"author":"Endless"},"fields":{"slug":"/how-to-use-case-statements-in-bash-scripting"}},"prev":{"excerpt":"Quick tutorial today to show the usage of pushd and popd commands for your Bash scripts, Lets get started! Quite…","frontmatter":{"title":"How to use 'pushd' and 'popd' statements in Bash scripting","cover":"https://picsum.photos/id/133/2500/1000","date":"2019-10-05"},"fields":{"slug":"/how-to-use-pushd-and-popd-statements-in-bash-scripting"}},"next":{"excerpt":"Google Chrome extensions are awesome, lets make one together! As we saw in  THIS  previous tutorial,\nit's…","frontmatter":{"title":"How to make a Google Chrome extension","cover":"https://picsum.photos/id/249/2500/1000","date":"2019-08-17"},"fields":{"slug":"/how-to-make-a-google-chrome-extension"}},"authors":{"edges":[{"node":{"uid":"Endless","name":"Endless","image":"https://api.adorable.io/avatars/285/pwpwpw.png","url":"https://github.com/RH-sdavey/sean-will-help-you","bio":"Endless Will Help You"}},{"node":{"uid":"Weez","name":"Salloweezy","image":"https://api.adorable.io/avatars/124/weezzzy.png","url":"http://gatsbyjs.org/","bio":"."}},{"node":{"uid":"Sean","name":"Sean","image":"https://api.adorable.io/avatars/124/weez.png","url":"https://github.com/RH-sdavey/sean-will-help-you","bio":"SEAN User created for SWHY"}},{"node":{"uid":"casper","name":"Casper User","image":"https://api.adorable.io/avatars/124/seasz.png","url":"http://gatsbyjs.org/","bio":"Yeah, I like animals better than people sometimes... Especially dogs. Dogs are the best. Every time you come home, they act like they haven't seen you in a year. And the good thing about dogs... is they got different dogs for different people."}},{"node":{"uid":"guinevere","name":"Guinevere Kuiper","image":"https://api.adorable.io/avatars/282/seaszss.png","url":"https://randomuser.me/api/?seed=user1","bio":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam laoreet lorem nec ligula aliquet, porta blandit augue luctus. Vivamus ac quam diam. Sed vestibulum pharetra hendrerit."}}]}},"pageContext":{"slug":"/how-to-use-case-statements-in-bash-scripting","total":12,"prev":"/how-to-use-pushd-and-popd-statements-in-bash-scripting","next":"/how-to-make-a-google-chrome-extension"}}