<?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: Shell Script Examples: case, count, for, if, while and User input</title>
	<atom:link href="http://rhau.se/2009/04/17/shell-script-examples-case-count-for-if-while-and-user-input/feed/" rel="self" type="application/rss+xml" />
	<link>http://rhau.se/2009/04/17/shell-script-examples-case-count-for-if-while-and-user-input/</link>
	<description>The home of Thorsten Rhau on the Internet</description>
	<lastBuildDate>Sun, 08 Jan 2012 01:40:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Thorsten</title>
		<link>http://rhau.se/2009/04/17/shell-script-examples-case-count-for-if-while-and-user-input/comment-page-1/#comment-2187</link>
		<dc:creator>Thorsten</dc:creator>
		<pubDate>Sun, 27 Nov 2011 08:45:11 +0000</pubDate>
		<guid isPermaLink="false">http://rhau.se/?p=248#comment-2187</guid>
		<description>Here is a non complete sample of how you can solve the problem. Please observe that bc is used instead of expr for calculations with decimals. The scale variable tells bc how many decimals to use when computing the numbers.

#!/bin/bash
clear
echo -n &quot;First number: &quot;
read N1

echo -n &quot;Second number: &quot;
read N2

echo -n &quot;Third number: &quot;
read N3

echo &quot;
A Add
M Multiply
V Average
&quot;
echo -n &quot;Please choose A, M or V: &quot;
read JOB

case $JOB in
  a&#124;A)
    expr $N1 + $N2 + $N3
    ;;
  m&#124;M)
    expr $N1 \* $N2 \* $N3
    ;;
  v&#124;V)
    TOTAL=`expr $N1 + $N2 + $N3`
    echo &quot;scale=2;$TOTAL / 3 &quot; &#124; bc -l
    ;;
  *) echo wrong choice;;
esac</description>
		<content:encoded><![CDATA[<p>Here is a non complete sample of how you can solve the problem. Please observe that bc is used instead of expr for calculations with decimals. The scale variable tells bc how many decimals to use when computing the numbers.</p>
<p>#!/bin/bash<br />
clear<br />
echo -n &#8220;First number: &#8221;<br />
read N1</p>
<p>echo -n &#8220;Second number: &#8221;<br />
read N2</p>
<p>echo -n &#8220;Third number: &#8221;<br />
read N3</p>
<p>echo &#8221;<br />
A Add<br />
M Multiply<br />
V Average<br />
&#8221;<br />
echo -n &#8220;Please choose A, M or V: &#8221;<br />
read JOB</p>
<p>case $JOB in<br />
  a|A)<br />
    expr $N1 + $N2 + $N3<br />
    ;;<br />
  m|M)<br />
    expr $N1 \* $N2 \* $N3<br />
    ;;<br />
  v|V)<br />
    TOTAL=`expr $N1 + $N2 + $N3`<br />
    echo &#8220;scale=2;$TOTAL / 3 &#8221; | bc -l<br />
    ;;<br />
  *) echo wrong choice;;<br />
esac</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thorsten</title>
		<link>http://rhau.se/2009/04/17/shell-script-examples-case-count-for-if-while-and-user-input/comment-page-1/#comment-2185</link>
		<dc:creator>Thorsten</dc:creator>
		<pubDate>Sun, 27 Nov 2011 08:18:38 +0000</pubDate>
		<guid isPermaLink="false">http://rhau.se/?p=248#comment-2185</guid>
		<description>I would use “read” to get user input. Example:
#!/bin/bash
read USERINPUT
echo $USERINPUT

For the math bit there is a nifty utility called expr. Example:
expr 12 + 12

will return the result of 24

I hope that this helps you
/thorsten</description>
		<content:encoded><![CDATA[<p>I would use “read” to get user input. Example:<br />
#!/bin/bash<br />
read USERINPUT<br />
echo $USERINPUT</p>
<p>For the math bit there is a nifty utility called expr. Example:<br />
expr 12 + 12</p>
<p>will return the result of 24</p>
<p>I hope that this helps you<br />
/thorsten</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bigron</title>
		<link>http://rhau.se/2009/04/17/shell-script-examples-case-count-for-if-while-and-user-input/comment-page-1/#comment-2180</link>
		<dc:creator>bigron</dc:creator>
		<pubDate>Sat, 26 Nov 2011 23:23:55 +0000</pubDate>
		<guid isPermaLink="false">http://rhau.se/?p=248#comment-2180</guid>
		<description>Hi i would like to know how to write a math script that ask the user for three numbers. gives the user three options to choose from: add,multiply and average. I also would like to use a case statement to make it work, save as one function.

Thanks.</description>
		<content:encoded><![CDATA[<p>Hi i would like to know how to write a math script that ask the user for three numbers. gives the user three options to choose from: add,multiply and average. I also would like to use a case statement to make it work, save as one function.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

