<?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: Zero Padding in Bash</title>
	<atom:link href="http://jonathanwagner.net/2007/04/zero-padding-in-bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/</link>
	<description>The webspace of Jonathan Wagner</description>
	<lastBuildDate>Wed, 17 Feb 2010 16:41:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jonathan</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-1094</link>
		<dc:creator>Jonathan</dc:creator>
		<pubDate>Wed, 17 Feb 2010 16:41:04 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-1094</guid>
		<description>@cdaaawg: It works if you type it yourself.  The blog software replaced the second quotation mark of the padding variable in Benoit&#039;s post with a fancy one.</description>
		<content:encoded><![CDATA[<p>@cdaaawg: It works if you type it yourself.  The blog software replaced the second quotation mark of the padding variable in Benoit&#8217;s post with a fancy one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cdaaawg</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-1093</link>
		<dc:creator>cdaaawg</dc:creator>
		<pubDate>Wed, 17 Feb 2010 16:27:14 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-1093</guid>
		<description>@Benoit Terradillos
Running your code under bash 3.2.39(1), I get the following output:
00000″0
00000″1
00000″2
00000″3
00000″4
00000″5
00000″6
00000″7
00000″8
00000″9
0000″10

Bizarre!

-- Carl</description>
		<content:encoded><![CDATA[<p>@Benoit Terradillos<br />
Running your code under bash 3.2.39(1), I get the following output:<br />
00000″0<br />
00000″1<br />
00000″2<br />
00000″3<br />
00000″4<br />
00000″5<br />
00000″6<br />
00000″7<br />
00000″8<br />
00000″9<br />
0000″10</p>
<p>Bizarre!</p>
<p>&#8211; Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Benoît Terradillos</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-1060</link>
		<dc:creator>Benoît Terradillos</dc:creator>
		<pubDate>Fri, 29 Jan 2010 17:37:36 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-1060</guid>
		<description>Even more simple (based on Hernan solution):

padding=&quot;00000&quot; # put as much zeros as you want.
for ((i=0; i&lt;31; i+=1))
do
  echo ${padding:${#i}}$i
done</description>
		<content:encoded><![CDATA[<p>Even more simple (based on Hernan solution):</p>
<p>padding=&#8221;00000&#8243; # put as much zeros as you want.<br />
for ((i=0; i&lt;31; i+=1))<br />
do<br />
  echo ${padding:${#i}}$i<br />
done</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A grateful visitor</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-951</link>
		<dc:creator>A grateful visitor</dc:creator>
		<pubDate>Mon, 05 Oct 2009 07:16:39 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-951</guid>
		<description>ZOMG, you have no idea how much this helped a &#039;nix n00b like me.

2 years on and this webpage is still helping people.

Thanks a lot!</description>
		<content:encoded><![CDATA[<p>ZOMG, you have no idea how much this helped a &#8216;nix n00b like me.</p>
<p>2 years on and this webpage is still helping people.</p>
<p>Thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krayon (Todd Harbour)</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-940</link>
		<dc:creator>Krayon (Todd Harbour)</dc:creator>
		<pubDate>Fri, 04 Sep 2009 17:31:40 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-940</guid>
		<description>It would appear this blog software messed with my comment :(

The 3rd and 4th lines were merged into one.  They should be:

[ $1 -gt $expo ] AMPAMP { echo $1; return; }
formatd=$(($1 + $expo))

where AMPAMP is 2 ampersands.</description>
		<content:encoded><![CDATA[<p>It would appear this blog software messed with my comment :(</p>
<p>The 3rd and 4th lines were merged into one.  They should be:</p>
<p>[ $1 -gt $expo ] AMPAMP { echo $1; return; }<br />
formatd=$(($1 + $expo))</p>
<p>where AMPAMP is 2 ampersands.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krayon (Todd Harbour)</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-939</link>
		<dc:creator>Krayon (Todd Harbour)</dc:creator>
		<pubDate>Fri, 04 Sep 2009 17:27:05 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-939</guid>
		<description>I use this rather &quot;simple&quot; solution, somewhat similar to Heman&#039;s, though it requires &gt;= bash 2.02:

function zeropad {
  expo=$((10 ** $2))
  [ $1 -gt $expo ] &amp;formatd=$(($1 + $expo))
  echo ${formatd:1}
}

Example:
  zeropad 59 10
0000000059</description>
		<content:encoded><![CDATA[<p>I use this rather &#8220;simple&#8221; solution, somewhat similar to Heman&#8217;s, though it requires &gt;= bash 2.02:</p>
<p>function zeropad {<br />
  expo=$((10 ** $2))<br />
  [ $1 -gt $expo ] &amp;formatd=$(($1 + $expo))<br />
  echo ${formatd:1}<br />
}</p>
<p>Example:<br />
  zeropad 59 10<br />
0000000059</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hernan</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-838</link>
		<dc:creator>Hernan</dc:creator>
		<pubDate>Tue, 16 Jun 2009 22:42:46 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-838</guid>
		<description>Calling printf will create a new process every time; this may be a little slow for some applications. A better performing example:

#!/bin/bash

(( million = 1000000 ))
(( index = 1 ))

while [ $index -lt 500000 ]
do
   (( printme = index + million ))
   (( index = index + 1 ))
   echo ${printme:1}
done

(See the &quot;Shell Parameter Expansion&quot; section of the bash manual for an explanation of what ${printme:1} does.)

On my machine at least (running Debian 4.0; bash v3.1.17) this is 12x faster than the printf version.

The &quot;printf&quot; solution is way more legible, of course.</description>
		<content:encoded><![CDATA[<p>Calling printf will create a new process every time; this may be a little slow for some applications. A better performing example:</p>
<p>#!/bin/bash</p>
<p>(( million = 1000000 ))<br />
(( index = 1 ))</p>
<p>while [ $index -lt 500000 ]<br />
do<br />
   (( printme = index + million ))<br />
   (( index = index + 1 ))<br />
   echo ${printme:1}<br />
done</p>
<p>(See the &#8220;Shell Parameter Expansion&#8221; section of the bash manual for an explanation of what ${printme:1} does.)</p>
<p>On my machine at least (running Debian 4.0; bash v3.1.17) this is 12x faster than the printf version.</p>
<p>The &#8220;printf&#8221; solution is way more legible, of course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jimmy</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-754</link>
		<dc:creator>jimmy</dc:creator>
		<pubDate>Fri, 24 Apr 2009 22:06:25 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-754</guid>
		<description>neat tip -- thanks!!</description>
		<content:encoded><![CDATA[<p>neat tip &#8212; thanks!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike H</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-738</link>
		<dc:creator>Mike H</dc:creator>
		<pubDate>Sun, 15 Mar 2009 00:38:47 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-738</guid>
		<description>thanks a plenty for the printf, jot and sed info guys.. now I have my script sorted and saving me a huge amount of time when it comes to the image files I am processing.

cheers</description>
		<content:encoded><![CDATA[<p>thanks a plenty for the printf, jot and sed info guys.. now I have my script sorted and saving me a huge amount of time when it comes to the image files I am processing.</p>
<p>cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Logan</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-710</link>
		<dc:creator>Logan</dc:creator>
		<pubDate>Wed, 14 Jan 2009 06:05:45 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-710</guid>
		<description>for ((i=1;i&lt;=11;i+=1)); do
s=`printf &quot;%02d&quot; $i`;
echo $s;
done

01
02
03
04
05
06
07
08
09
10
11</description>
		<content:encoded><![CDATA[<p>for ((i=1;i&lt;=11;i+=1)); do<br />
s=`printf &#8220;%02d&#8221; $i`;<br />
echo $s;<br />
done</p>
<p>01<br />
02<br />
03<br />
04<br />
05<br />
06<br />
07<br />
08<br />
09<br />
10<br />
11</p>
]]></content:encoded>
	</item>
</channel>
</rss>
