{"id":407,"date":"2026-02-10T03:51:09","date_gmt":"2026-02-10T03:51:09","guid":{"rendered":"https:\/\/mitalgoswami.in\/?p=407"},"modified":"2026-02-17T04:37:30","modified_gmt":"2026-02-17T04:37:30","slug":"switch-command","status":"publish","type":"post","link":"https:\/\/mitalgoswami.in\/?p=407","title":{"rendered":"switch command"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">&#x1f500; What is switch case?<\/h2>\n\n\n\n<p>In <strong>shell scripting<\/strong>, <code>switch case<\/code> is written as <strong><code>case<\/code><\/strong>.<br>It is used to <strong>match a value against multiple patterns<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">&#x1f539; Syntax<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>case variable in\n    pattern1)\n        commands ;;\n    pattern2)\n        commands ;;\n    *)\n        default commands ;;\nesac<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Example 3: Check character type<\/h1>\n\n\n\n<p>#!\/bin\/bash<\/p>\n\n\n\n<p>read ch<\/p>\n\n\n\n<p>case $ch in<br>[a-z])<br>echo &#8220;Lowercase letter&#8221;<br>;;<br>[A-Z])<br>echo &#8220;Uppercase letter&#8221;<br>;;<br>[0-9])<br>echo &#8220;Digit&#8221;<br>;;<br>*)<br>echo &#8220;Special character&#8221;<br>;;<br>esac<\/p>\n\n\n\n<p>&#x2705; Example 4: File type check<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>read file<\/p>\n\n\n\n<p>case $file in<br>*.sh)<br>echo &#8220;Shell script file&#8221;<br>;;<br>*.txt)<br>echo &#8220;Text file&#8221;<br>;;<br>*)<br>echo &#8220;Unknown file type&#8221;<br>;;<br>esac<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f500; What is switch case? In shell scripting, switch case is written as case.It is used to match a value against multiple patterns. &#x1f539; Syntax Example 3: Check character type #!\/bin\/bash read ch case $ch in[a-z])echo &#8220;Lowercase letter&#8221;;;[A-Z])echo &#8220;Uppercase letter&#8221;;;[0-9])echo &#8220;Digit&#8221;;;*)echo &#8220;Special character&#8221;;;esac &#x2705; Example 4: File type check !\/bin\/bash read file case $file in*.sh)echo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-407","post","type-post","status-publish","format-standard","hentry","category-unix"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=407"}],"version-history":[{"count":2,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/407\/revisions"}],"predecessor-version":[{"id":409,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/407\/revisions\/409"}],"wp:attachment":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}