<?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: Win a book by debugging this shell script</title>
	<atom:link href="http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/feed" rel="self" type="application/rss+xml" />
	<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html</link>
	<description>Learn the UNIX/Linux command line</description>
	<lastBuildDate>Mon, 06 Jun 2011 01:35:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Al</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-12550</link>
		<dc:creator>Al</dc:creator>
		<pubDate>Fri, 20 Jun 2008 13:13:01 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-12550</guid>
		<description>The biggest problem I found with for is when dealing with space separated multi-word data input. &quot;For&quot; doesn&#039;t know where the real data begins or ends.

My vote is for extending the subshell with ()&#039;s giving you a chance to deal with vars. Good point. Thank you.</description>
		<content:encoded><![CDATA[<p>The biggest problem I found with for is when dealing with space separated multi-word data input. &#8220;For&#8221; doesn&#8217;t know where the real data begins or ends.</p>
<p>My vote is for extending the subshell with ()&#8217;s giving you a chance to deal with vars. Good point. Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bobby</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-11575</link>
		<dc:creator>Bobby</dc:creator>
		<pubDate>Sat, 14 Jun 2008 19:18:36 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-11575</guid>
		<description>The problem is with the scope of the calls and the variable being set local withing the function.  If the variable had been set in the script instead of the funciton the return value would have been 0.</description>
		<content:encoded><![CDATA[<p>The problem is with the scope of the calls and the variable being set local withing the function.  If the variable had been set in the script instead of the funciton the return value would have been 0.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sulakshana</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-3677</link>
		<dc:creator>Sulakshana</dc:creator>
		<pubDate>Wed, 20 Feb 2008 12:49:58 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-3677</guid>
		<description>The 
local retVal = 1

and retVal inside the do while loop are treated differently by the shell.

whatever the loop does, the outer retVal has no effect.

So successful or unsuccesful, the function will exit with value =1.</description>
		<content:encoded><![CDATA[<p>The<br />
local retVal = 1</p>
<p>and retVal inside the do while loop are treated differently by the shell.</p>
<p>whatever the loop does, the outer retVal has no effect.</p>
<p>So successful or unsuccesful, the function will exit with value =1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mangesh</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-233</link>
		<dc:creator>Mangesh</dc:creator>
		<pubDate>Thu, 01 Nov 2007 18:18:08 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-233</guid>
		<description>This is problem of scope.
Scope of shell is not accessible inside subshell.
If we do not initialize or declare variable &quot;retVal&quot; before while loop (i.e. remove statement retVal=1 ), the script will run fine.</description>
		<content:encoded><![CDATA[<p>This is problem of scope.<br />
Scope of shell is not accessible inside subshell.<br />
If we do not initialize or declare variable &#8220;retVal&#8221; before while loop (i.e. remove statement retVal=1 ), the script will run fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adny</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-43</link>
		<dc:creator>Adny</dc:creator>
		<pubDate>Tue, 16 Oct 2007 10:28:53 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-43</guid>
		<description>Exporting retVal won&#039;t work - the subshell will have access to its copy of the parent&#039;s variable, not to the parent&#039;s variable itself :)</description>
		<content:encoded><![CDATA[<p>Exporting retVal won&#8217;t work &#8211; the subshell will have access to its copy of the parent&#8217;s variable, not to the parent&#8217;s variable itself <img src='http://bashcurescancer.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-37</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 15 Oct 2007 22:27:27 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-37</guid>
		<description>PAshaRome,

Yes, thanks for the answer. Do not worry about the english.  Not everyone is going to get a copy, I&#039;ll let you know.

Thanks.</description>
		<content:encoded><![CDATA[<p>PAshaRome,</p>
<p>Yes, thanks for the answer. Do not worry about the english.  Not everyone is going to get a copy, I&#8217;ll let you know.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-36</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 15 Oct 2007 22:24:16 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-36</guid>
		<description>dosnlinux,

Yes, I could have exported the value. However, it seems inelegant.</description>
		<content:encoded><![CDATA[<p>dosnlinux,</p>
<p>Yes, I could have exported the value. However, it seems inelegant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-35</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 15 Oct 2007 22:22:33 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-35</guid>
		<description>Jim,

Here&#039;s a test that shows that the while loop is much faster.  I am quite surprised...

&lt;code&gt;
$ ./whileForLoopTest.sh
55
31
$ ./whileForLoopTest.sh
54
30
&lt;/code&gt;

Heres the script.

&lt;code&gt;
$ cat whileForLoopTest.sh
#!/bin/bash
run()
{
        for((I=0; I &lt; 500; I++))
        do
                eval &quot;$@&quot;
        done
}


forTest()
{
        for user in $( ps -e -o user )
        do
                :
        done
}

whileTest()
{
        ps -e -o user &#124; \
        while read user
        do
                :
        done
}

start=$( date +%s )
run forTest
expr $( date +%s ) - $start

start=$( date +%s )
run whileTest
expr $( date +%s ) - $start
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Jim,</p>
<p>Here&#8217;s a test that shows that the while loop is much faster.  I am quite surprised&#8230;</p>
<p><code><br />
$ ./whileForLoopTest.sh<br />
55<br />
31<br />
$ ./whileForLoopTest.sh<br />
54<br />
30<br />
</code></p>
<p>Heres the script.</p>
<p><code><br />
$ cat whileForLoopTest.sh<br />
#!/bin/bash<br />
run()<br />
{<br />
        for((I=0; I < 500; I++))<br />
        do<br />
                eval "$@"<br />
        done<br />
}</p>
<p>forTest()<br />
{<br />
        for user in $( ps -e -o user )<br />
        do<br />
                :<br />
        done<br />
}</p>
<p>whileTest()<br />
{<br />
        ps -e -o user | \<br />
        while read user<br />
        do<br />
                :<br />
        done<br />
}</p>
<p>start=$( date +%s )<br />
run forTest<br />
expr $( date +%s ) - $start</p>
<p>start=$( date +%s )<br />
run whileTest<br />
expr $( date +%s ) - $start<br />
</code></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PAshaRome</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-34</link>
		<dc:creator>PAshaRome</dc:creator>
		<pubDate>Mon, 15 Oct 2007 22:05:44 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-34</guid>
		<description>Sorry for my eng.

There is a scope problem.

retVal inside the loop is not the same of retVal outside the loop.

Tnx. (I would like ti have a copy of book ;) )</description>
		<content:encoded><![CDATA[<p>Sorry for my eng.</p>
<p>There is a scope problem.</p>
<p>retVal inside the loop is not the same of retVal outside the loop.</p>
<p>Tnx. (I would like ti have a copy of book <img src='http://bashcurescancer.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim</title>
		<link>http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html/comment-page-1#comment-33</link>
		<dc:creator>Jim</dc:creator>
		<pubDate>Mon, 15 Oct 2007 21:49:39 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/win-a-book-by-debugging-this-shell-script.html#comment-33</guid>
		<description>My understanding has always been that a for loop is better for iterating a definable list (which we can get with the grep statement in this example) than the more open ended while loop anyway.  

I wonder if there is a way (with bash) to quantify the relative difference.  It would seem, at first blush, that the while loop would take more allocated memory and might be slower.

The for loop probably has drawbacks as well.

Anybody have any numbers that they can share?</description>
		<content:encoded><![CDATA[<p>My understanding has always been that a for loop is better for iterating a definable list (which we can get with the grep statement in this example) than the more open ended while loop anyway.  </p>
<p>I wonder if there is a way (with bash) to quantify the relative difference.  It would seem, at first blush, that the while loop would take more allocated memory and might be slower.</p>
<p>The for loop probably has drawbacks as well.</p>
<p>Anybody have any numbers that they can share?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.138 seconds -->
<!-- Cached page served by WP-Cache -->

