{"id":2371,"date":"2015-11-27T10:20:15","date_gmt":"2015-11-27T10:20:15","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=2371"},"modified":"2015-11-27T10:20:15","modified_gmt":"2015-11-27T10:20:15","slug":"case-statements-in-bash","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=2371","title":{"rendered":"Case statements in BASH"},"content":{"rendered":"<p>The case construct in bash shell allows us to test strings against patterns that can contain wild card characters. Bash case statement is the simplest form of the\u00a0<a href=\"http:\/\/www.thegeekstuff.com\/2010\/06\/bash-if-statement-examples\/\">bash if-then-else statement<\/a>.<\/p>\n<p>Syntax of bash case statement.<\/p>\n<pre>case expression in\r\n    pattern1 )\r\n        statements ;;\r\n    pattern2 )\r\n        statements ;;\r\n    ...\r\nesac\r\n<\/pre>\n<p>Following are the key points of bash case statements:<\/p>\n<ul>\n<li>Case statement first expands the expression and tries to match it against each pattern.<\/li>\n<li>When a match is found all of the associated statements until the double semicolon (;;) are executed.<\/li>\n<li>After the first match, case terminates with the exit status of the last command that was executed. \u00a0So All wildcards MUST go towards the end of the Case statement<\/li>\n<li>If there is no match, exit status of case is zero.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/blog.designed79.co.uk\/wp-content\/uploads\/2015\/11\/5-Bash-Case-Statement-Examples.pdf\">5 Bash Case Statement Examples<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The case construct in bash shell allows us to test strings against patterns that can contain wild card characters. Bash case statement [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2371","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2371"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2371\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}