{"id":52,"date":"2024-12-11T06:28:33","date_gmt":"2024-12-11T06:28:33","guid":{"rendered":"https:\/\/mitalgoswami.in\/?p=52"},"modified":"2025-07-17T06:51:36","modified_gmt":"2025-07-17T06:51:36","slug":"unix-switch-case","status":"publish","type":"post","link":"https:\/\/mitalgoswami.in\/?p=52","title":{"rendered":"Unix Switch Case"},"content":{"rendered":"\n<p>variables type<br>1)shell<br>2)system\/environment<br>3) userdefine variable<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;File Name: $0&#8221;<br>echo &#8220;First Parameter : $1&#8221;<br>echo &#8220;Second Parameter : $2&#8221;<br>echo &#8220;Quoted Values: $@&#8221;<br>echo &#8220;Quoted Values: $*&#8221;<br>echo &#8220;Total Number of Parameters : $#&#8221;<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/sh<\/h1>\n\n\n\n<p>for TOKEN in $*<br>do<br>echo $TOKEN<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">done<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;Enter first number&#8221;<br>read x<br>echo &#8220;Enter second number&#8221;<br>read y<br>sum=$(( $x + $y ))<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">echo &#8220;The result of addition=$sum&#8221;<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;enter your choice&#8221;<br>read mycase<br>case $mycase in<br>1) echo &#8220;You selected unix&#8221;;;<br>2) echo &#8220;You selected php&#8221;;;<br>3) echo &#8220;You selected java&#8221;;;<br>4) echo &#8220;You selected c++&#8221;;;<br>5) exit<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">esac<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;enter vowel&#8221;<br>read mycase<br>case $mycase in<br>&#8216;a&#8217;) echo &#8220;vowel&#8221;;;<br>&#8216;e&#8217;) echo &#8220;vowel&#8221;;;<br>&#8216;i&#8217;) echo &#8220;vowel&#8221;;;<br>&#8216;o&#8217;) echo &#8220;vowel&#8221;;;<br>&#8216;u&#8217;) echo &#8220;vowel&#8221;;;<br>*) echo &#8220;consonent&#8221; ;;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">esac<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;Enter your lucky number&#8221;<br>read n<br>case $n in<br>101)<br>echo echo &#8220;You got 1stprize&#8221; ;;<br>510)<br>echo &#8220;You got 2nd prize&#8221; ;;<br>999)<br>echo &#8220;You got 3rd prize&#8221; ;;<br>*)<br>echo &#8220;Sorry,tryfor the next time&#8221; ;;<br>esac<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>for i in {1..5}<br>do<br>sleep $i &amp;<br>done<br>echo &#8220;Background processes started\u2026&#8221;<br>wait<br>echo &#8220;All processes have completed!&#8221;<br>~<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>test 5 -gt 2 &amp;&amp; echo &#8220;Yes&#8221;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">test 1 -lt 2 &amp;&amp; echo &#8220;Yes&#8221;<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>if [ <code>expr $a % 2<\/code> == 0 -a $a -gt 10 ]<br>then<br>echo &#8220;$a is even and greater than 10.&#8221;<br>else<br>echo &#8220;$a failed the test.&#8221;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">fi<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>for (( i=1 ; i&lt;=5 ; i++ ))<br>do<br>for (( j=1 ; j&lt;=i ; j++ ))<br>do<br>echo -n &#8220;*&#8221;<br>done<br>echo &#8221; &#8220;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">done<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>for (( i=1 ; i&lt;=5 ; i++ ))<br>do<br>for (( j=1 ; j&lt;=i ; j++ ))<br>do<br>echo -n &#8220;$i&#8221;<br>done<br>echo &#8221; &#8220;<br>done<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\/\/was multiplication table<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;Enter a Number&#8221;<br>read n<br>i=1<\/p>\n\n\n\n<p>while [ $i -le 10 ]<br>do<br>echo &#8221; $n x $i = $(( n * i ))&#8221;<br>i=$(( i + 1 ))<br>done<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>rows=5<br>for((i=rows; i&gt;=1; i&#8211;))<br>do<br>for((j=1; j&lt;=i; j++))<br>do<br>echo -n &#8220;* &#8220;<br>done<br>echo<br>done<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>clear<br>p=$1<br>r=$2<br>n=$3<br>let int=<code>expr $p \\* $r \\* $n<\/code><br>int=<code>expr $int \/ 100<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">echo &#8220;simple interest , $int&#8221;<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;enter the year&#8221;<\/p>\n\n\n\n<p>read a<\/p>\n\n\n\n<p>year= $a<\/p>\n\n\n\n<p>a=$(( $a %4 ))<\/p>\n\n\n\n<p>if [ $a -eq 0 ];<\/p>\n\n\n\n<p>then<br>echo &#8220;$year is leap&#8221;<\/p>\n\n\n\n<p>else<br>echo &#8220;$year is not a leap year&#8221;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">fi<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;Enter any number&#8221;<br>read n<\/p>\n\n\n\n<p>if [[ ( $n -eq 15 || $n -eq 45 ) ]]<br>then<br>echo &#8220;You won the game&#8221;<br>else<br>echo &#8220;You lost the game&#8221;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">fi<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;Enter your lucky number&#8221;<br>read n<\/p>\n\n\n\n<p>if [ $n -eq 101 ];<br>then<br>echo &#8220;You got 1st prize&#8221;<br>elif [ $n -eq 510 ];<br>then<br>echo &#8220;You got 2nd prize&#8221;<br>elif [ $n -eq 999 ];<br>then<br>echo &#8220;You got 3rd prize&#8221;<\/p>\n\n\n\n<p>else<br>echo &#8220;Sorry, try for the next time&#8221;<br>fi<\/p>\n\n\n\n<p>========================================<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;enter file name&#8221;<br>read fname<br>if [ -f $fname ]; then<br>echo &#8220;$fname file exist&#8221;<br>else<br>echo &#8220;sorry, $fname file does not exist&#8221;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">fi<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>function F1()<br>{<br>echo &#8216;I like bash programming&#8217;<br>}<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">F1<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>echo &#8220;Enter directory name&#8221;<br>read ndir<br>if [ -d &#8220;$ndir&#8221; ]<br>then<br>echo &#8220;Directory exist&#8221;<br>else<br><code>mkdir $ndir<\/code><br>echo &#8220;Directory created&#8221;<br>fi<\/p>\n","protected":false},"excerpt":{"rendered":"<p>variables type1)shell2)system\/environment3) userdefine variable !\/bin\/bash echo &#8220;File Name: $0&#8221;echo &#8220;First Parameter : $1&#8221;echo &#8220;Second Parameter : $2&#8221;echo &#8220;Quoted Values: $@&#8221;echo &#8220;Quoted Values: $*&#8221;echo &#8220;Total Number of Parameters : $#&#8221; !\/bin\/sh for TOKEN in $*doecho $TOKEN done !\/bin\/bash echo &#8220;Enter first number&#8221;read xecho &#8220;Enter second number&#8221;read ysum=$(( $x + $y )) echo &#8220;The result of addition=$sum&#8221; [&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-52","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\/52","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=52"}],"version-history":[{"count":1,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}