<?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: Keeping You in the Loop &#8211; Bash For, While, Until Loop Examples</title>
	<atom:link href="http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/</link>
	<description>Guides, HowTos and Tips for Technology Geeks</description>
	<lastBuildDate>Thu, 09 Feb 2012 11:52:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: jalal hajigholamali</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-117041</link>
		<dc:creator>jalal hajigholamali</dc:creator>
		<pubDate>Mon, 11 Jul 2011 08:33:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-117041</guid>
		<description>Hi,

great....</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>great&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adyxax</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-53042</link>
		<dc:creator>adyxax</dc:creator>
		<pubDate>Fri, 09 Jul 2010 12:48:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-53042</guid>
		<description>Yes, I will grant you that those are both external commands. I just can&#039;t stand to see people using the awk and sed here and there because, as wonderfull and lovely those commands are, it&#039;s quite overkill for so simple tasks.

Programming well in *sh is related to how many commands you know/understand, and using simple commands to do simple tasks is always good for your karma (and it&#039;s more readable as far as bash is readable).

Otherwise yes, the efficient way to do this replacement is using bash internals, as you suggest.</description>
		<content:encoded><![CDATA[<p>Yes, I will grant you that those are both external commands. I just can&#8217;t stand to see people using the awk and sed here and there because, as wonderfull and lovely those commands are, it&#8217;s quite overkill for so simple tasks.</p>
<p>Programming well in *sh is related to how many commands you know/understand, and using simple commands to do simple tasks is always good for your karma (and it&#8217;s more readable as far as bash is readable).</p>
<p>Otherwise yes, the efficient way to do this replacement is using bash internals, as you suggest.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris F.A. Johnson</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-52900</link>
		<dc:creator>Chris F.A. Johnson</dc:creator>
		<pubDate>Thu, 08 Jul 2010 17:03:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-52900</guid>
		<description>Using basename is no better than awk. They are both external commands.
The shell can do it internally using parameter expansion:

filename=whatever.zip
name=${filename%.*}</description>
		<content:encoded><![CDATA[<p>Using basename is no better than awk. They are both external commands.<br />
The shell can do it internally using parameter expansion:</p>
<p>filename=whatever.zip<br />
name=${filename%.*}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adyxax</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-52886</link>
		<dc:creator>adyxax</dc:creator>
		<pubDate>Thu, 08 Jul 2010 14:56:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-52886</guid>
		<description>I saw you are using awk to remove the .zip extension using awk in the first example :
# Skip the extension .zip
dirname=`echo ${file} &#124; awk -F&#039;.&#039; &#039;{print $1}&#039;`

I just wanted to suggest using the &quot;basename&quot; command for this kind of purposes : basename ${file} .zip</description>
		<content:encoded><![CDATA[<p>I saw you are using awk to remove the .zip extension using awk in the first example :<br />
# Skip the extension .zip<br />
dirname=`echo ${file} | awk -F&#8217;.&#8217; &#8216;{print $1}&#8217;`</p>
<p>I just wanted to suggest using the &#8220;basename&#8221; command for this kind of purposes : basename ${file} .zip</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris F.A. Johnson</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-52604</link>
		<dc:creator>Chris F.A. Johnson</dc:creator>
		<pubDate>Tue, 06 Jul 2010 15:14:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-52604</guid>
		<description>man bash:

Parameter Expansion
   ...
       ${parameter#word}
       ${parameter##word}
              Remove matching prefix pattern.  The word is expanded to produce
              a pattern just as in pathname expansion.  If the pattern matches
              the beginning of the value of parameter, then the result of the
              expansion is the expanded value of parameter with the shortest
              matching pattern (the &#039;&#039;#&#039;&#039; case) or the longest matching
              pattern (the &#039;&#039;##&#039;&#039; case) deleted.  If parameter is @ or *, the
              pattern removal operation is applied to each positional
              parameter in turn, and the expansion is the resultant list.  If
              parameter is an array variable subscripted with @ or *, the
              pattern removal operation is applied to each member of the array
              in turn, and the expansion is the resultant list.</description>
		<content:encoded><![CDATA[<p>man bash:</p>
<p>Parameter Expansion<br />
   &#8230;<br />
       ${parameter#word}<br />
       ${parameter##word}<br />
              Remove matching prefix pattern.  The word is expanded to produce<br />
              a pattern just as in pathname expansion.  If the pattern matches<br />
              the beginning of the value of parameter, then the result of the<br />
              expansion is the expanded value of parameter with the shortest<br />
              matching pattern (the &#8221;#&#8221; case) or the longest matching<br />
              pattern (the &#8221;##&#8221; case) deleted.  If parameter is @ or *, the<br />
              pattern removal operation is applied to each positional<br />
              parameter in turn, and the expansion is the resultant list.  If<br />
              parameter is an array variable subscripted with @ or *, the<br />
              pattern removal operation is applied to each member of the array<br />
              in turn, and the expansion is the resultant list.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: insomnia</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-52603</link>
		<dc:creator>insomnia</dc:creator>
		<pubDate>Tue, 06 Jul 2010 14:19:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-52603</guid>
		<description>Thanks!Great job!
I have a question: what does &quot;##&quot; in  &quot;${file##/*/}&quot; means?</description>
		<content:encoded><![CDATA[<p>Thanks!Great job!<br />
I have a question: what does &#8220;##&#8221; in  &#8220;${file##/*/}&#8221; means?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris F.A. Johnson</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-52510</link>
		<dc:creator>Chris F.A. Johnson</dc:creator>
		<pubDate>Mon, 05 Jul 2010 21:33:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-52510</guid>
		<description>fs, those are only the same if $file begins with a slash.</description>
		<content:encoded><![CDATA[<p>fs, those are only the same if $file begins with a slash.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fs</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-52477</link>
		<dc:creator>fs</dc:creator>
		<pubDate>Mon, 05 Jul 2010 13:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-52477</guid>
		<description>Nice tut! thanks!
but in Bash For ... 1
shouldn&#039;t
${file##*/}
be the same as
${file##/*/}
or I&#039;m missing something?
By!</description>
		<content:encoded><![CDATA[<p>Nice tut! thanks!<br />
but in Bash For &#8230; 1<br />
shouldn&#8217;t<br />
${file##*/}<br />
be the same as<br />
${file##/*/}<br />
or I&#8217;m missing something?<br />
By!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris F.A. Johnson</title>
		<link>http://www.thegeekstuff.com/2010/06/bash-for-while-until-loop-examples/comment-page-1/#comment-51507</link>
		<dc:creator>Chris F.A. Johnson</dc:creator>
		<pubDate>Mon, 28 Jun 2010 08:28:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=5011#comment-51507</guid>
		<description>&gt; exec  while read line

That will not read the entire line if there is whitespace at the beginning or end of a line, and it will not read the line exactly as it is in the file if there are escaped characters in the line. The command should be:

while IFS= read -r line

&gt; echo $line

That will not print the line exactly as it was in the file if there are consecutive whitespace characters in the line. Multiple whitespace characters will be replaced by a single space. It should be:

echo &quot;$line&quot;

And even that will not print the line correctly if $line contains, for example, &quot;-n whatever&quot;. When the contents of a variable are unknown, use printf:

printf &quot;%s\n&quot; &quot;$line&quot;</description>
		<content:encoded><![CDATA[<p>&gt; exec  while read line</p>
<p>That will not read the entire line if there is whitespace at the beginning or end of a line, and it will not read the line exactly as it is in the file if there are escaped characters in the line. The command should be:</p>
<p>while IFS= read -r line</p>
<p>&gt; echo $line</p>
<p>That will not print the line exactly as it was in the file if there are consecutive whitespace characters in the line. Multiple whitespace characters will be replaced by a single space. It should be:</p>
<p>echo &#8220;$line&#8221;</p>
<p>And even that will not print the line correctly if $line contains, for example, &#8220;-n whatever&#8221;. When the contents of a variable are unknown, use printf:</p>
<p>printf &#8220;%s\n&#8221; &#8220;$line&#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Content Delivery Network via Amazon Web Services: CloudFront: static.thegeekstuff.com

Served from: www.thegeekstuff.com @ 2012-02-09 12:46:03 -->
