<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Bourne/bash shell scripts: case statement</title>
	<atom:link href="http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/</link>
	<description>Computer and technology tutorials and guides</description>
	<lastBuildDate>Thu, 09 Feb 2012 21:01:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ocho</title>
		<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/comment-page-1/#comment-53648</link>
		<dc:creator>Ocho</dc:creator>
		<pubDate>Fri, 27 Jan 2012 19:30:35 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-53648</guid>
		<description>read input
  case &quot;${input}&quot; in
    y&#124;Y&#124;yes&#124;YES&#124;Yes)
      echo &quot;Do some yes things...&quot;
      ;;
    n&#124;N&#124;no&#124;NO&#124;No)
      echo &quot;Do some no things&quot;
      ;;
    *)
      echo &quot;${input} is not a valid input. &quot;
      # loop back in via a function or return 1 or quit etc.
      ;;
  esac</description>
		<content:encoded><![CDATA[<p>read input<br />
  case &#8220;${input}&#8221; in<br />
    y|Y|yes|YES|Yes)<br />
      echo &#8220;Do some yes things&#8230;&#8221;<br />
      ;;<br />
    n|N|no|NO|No)<br />
      echo &#8220;Do some no things&#8221;<br />
      ;;<br />
    *)<br />
      echo &#8220;${input} is not a valid input. &#8221;<br />
      # loop back in via a function or return 1 or quit etc.<br />
      ;;<br />
  esac</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sony Sebastian</title>
		<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/comment-page-1/#comment-45679</link>
		<dc:creator>Sony Sebastian</dc:creator>
		<pubDate>Wed, 19 Jan 2011 17:43:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-45679</guid>
		<description>#!/bin/sh

echo &quot;Enter your choice:&quot;
read username

case &quot;$username&quot; in
  &#039;start&#039;)
        echo &#039;starting............&#039;;;
  &#039;stop&#039;)
        echo &#039;stopping...........&#039;;;
  &#039;restart&#039;)
        echo &#039;restarting.........&#039;;;
esac

##################
Output:
 ./test.sh

Enter your choice:
start
starting............</description>
		<content:encoded><![CDATA[<p>#!/bin/sh</p>
<p>echo &#8220;Enter your choice:&#8221;<br />
read username</p>
<p>case &#8220;$username&#8221; in<br />
  &#8217;start&#8217;)<br />
        echo &#8217;starting&#8230;&#8230;&#8230;&#8230;&#8217;;;<br />
  &#8217;stop&#8217;)<br />
        echo &#8217;stopping&#8230;&#8230;&#8230;..&#8217;;;<br />
  &#8216;restart&#8217;)<br />
        echo &#8216;restarting&#8230;&#8230;&#8230;&#8217;;;<br />
esac</p>
<p>##################<br />
Output:<br />
 ./test.sh</p>
<p>Enter your choice:<br />
start<br />
starting&#8230;&#8230;&#8230;&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Garry Hurley Jr</title>
		<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/comment-page-1/#comment-43079</link>
		<dc:creator>Garry Hurley Jr</dc:creator>
		<pubDate>Mon, 11 Oct 2010 16:27:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-43079</guid>
		<description>Simple.  You need to use the escape character on the switch, and you escape it as a parameter.  Here is a basic example of that line

#!/bin/bash
case $1 in
  %)
    echo &quot;%&quot;
    ;;
  *)
    echo &quot;*&quot;
    ;;
  *)
    echo &quot;none of the above&quot;
    ;;
esac

Sample output:

snoopy:~&gt;./testBash *
*

My suggestion is to use the &#039;x&#039; for multiplication instead if you don&#039;t want your users to have to escape the &#039;*&#039; every time they use the program.</description>
		<content:encoded><![CDATA[<p>Simple.  You need to use the escape character on the switch, and you escape it as a parameter.  Here is a basic example of that line</p>
<p>#!/bin/bash<br />
case $1 in<br />
  %)<br />
    echo &#8220;%&#8221;<br />
    ;;<br />
  *)<br />
    echo &#8220;*&#8221;<br />
    ;;<br />
  *)<br />
    echo &#8220;none of the above&#8221;<br />
    ;;<br />
esac</p>
<p>Sample output:</p>
<p>snoopy:~&gt;./testBash *<br />
*</p>
<p>My suggestion is to use the &#8216;x&#8217; for multiplication instead if you don&#8217;t want your users to have to escape the &#8216;*&#8217; every time they use the program.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/comment-page-1/#comment-38329</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Sun, 28 Mar 2010 14:37:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-38329</guid>
		<description>Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick</title>
		<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/comment-page-1/#comment-37947</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Fri, 05 Mar 2010 20:23:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-37947</guid>
		<description>Nice this one was really usefull, but the last one didn&#039;t seem to work for me.
It would whine about a syntax error, so I removes the ! in front and added a *) to catch all the rest, in the case I just did a echo &quot;parameter is valid&quot;

But thanx a lot</description>
		<content:encoded><![CDATA[<p>Nice this one was really usefull, but the last one didn&#8217;t seem to work for me.<br />
It would whine about a syntax error, so I removes the ! in front and added a *) to catch all the rest, in the case I just did a echo &#8220;parameter is valid&#8221;</p>
<p>But thanx a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: S.Raghu</title>
		<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/comment-page-1/#comment-31058</link>
		<dc:creator>S.Raghu</dc:creator>
		<pubDate>Sat, 13 Jun 2009 07:56:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-31058</guid>
		<description>How to branch if the value of the variable is &#039;*&#039; ?
For eg parameters passed to a program are 2 numbers and an arithmetical operand. </description>
		<content:encoded><![CDATA[<p>How to branch if the value of the variable is &#8216;*&#8217; ?<br />
For eg parameters passed to a program are 2 numbers and an arithmetical operand.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: newbie</title>
		<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/comment-page-1/#comment-29581</link>
		<dc:creator>newbie</dc:creator>
		<pubDate>Tue, 21 Apr 2009 04:29:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-29581</guid>
		<description>stdin means &quot;standard input&quot; from the keyboard (file descriptor=0)
stdout means &quot;standard output&quot; to the computer screen (file descriptor=1)
stderr means &quot;standard error&quot;; output for error messages (file descriptor=2)</description>
		<content:encoded><![CDATA[<p>stdin means &#8220;standard input&#8221; from the keyboard (file descriptor=0)<br />
stdout means &#8220;standard output&#8221; to the computer screen (file descriptor=1)<br />
stderr means &#8220;standard error&#8221;; output for error messages (file descriptor=2)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.tech-recipes.com/rx/212/bourne_bash_shell_scripts_case_statement/comment-page-1/#comment-26413</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 31 Dec 2008 09:28:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-26413</guid>
		<description>case &quot;$1&quot; in
  stdin&#124;
  -)
commands
;;

What does stdin&#124;
-) mean here?
Can somebody explain it?</description>
		<content:encoded><![CDATA[<p>case &#8220;$1&#8243; in<br />
  stdin|<br />
  -)<br />
commands<br />
;;</p>
<p>What does stdin|<br />
-) mean here?<br />
Can somebody explain it?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached (User agent is rejected)
Database Caching 2/15 queries in 1.060 seconds using memcached
Object Caching 381/385 objects using memcached

Served from: www.tech-recipes.com @ 2012-02-10 05:27:53 -->
