<?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>Fri, 11 Jun 2010 13:03:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Gengis</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-1413</link>
		<dc:creator>Gengis</dc:creator>
		<pubDate>Fri, 11 Jun 2010 13:03:13 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-1413</guid>
		<description>&quot;zeropad function&quot;, works like a charm to me, thank you very much.

In order to return something beyond my thanks, here is my script:

--

#!/bin/bash
EXPECTED_ARGS=3
COUNTEROFSHOTS=0
COUNTER=0
return=0
imageName=0

# define usage function
usage(){
    echo &quot;Usage: $0 shortNameForDatabase startNumber numberOfFiguresForEachNumber&quot;
    exit 1
}

help(){
    echo
    echo &quot;This script help the user in order to take multiple source images for the software X.&quot;
    echo
    echo &quot;1. Please make sure script Y is properly calibrated.&quot;
    echo &quot;2. Press any key in order to take one shot, Ctrl+c to quit&quot;
    echo
}

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

if [ $# -ne $EXPECTED_ARGS ]
then
    usage
    echo -n &quot;Press any key to take shot!&quot;
else
    COUNTER=$2
    help
    while [ 1 ]
    do
	read var_name
	zeropad $COUNTER $3
	imageName=$1$return.png
	echo ./Y $imageName 
	COUNTER=$((COUNTER+1))
	COUNTEROFSHOTS=$((COUNTEROFSHOTS+1))
	echo -n $COUNTEROFSHOTS&quot;.&quot;$imageName.&quot; done. Press any key to take shot!&quot;
    done
fi</description>
		<content:encoded><![CDATA[<p>&#8220;zeropad function&#8221;, works like a charm to me, thank you very much.</p>
<p>In order to return something beyond my thanks, here is my script:</p>
<p>&#8211;</p>
<p>#!/bin/bash<br />
EXPECTED_ARGS=3<br />
COUNTEROFSHOTS=0<br />
COUNTER=0<br />
return=0<br />
imageName=0</p>
<p># define usage function<br />
usage(){<br />
    echo &#8220;Usage: $0 shortNameForDatabase startNumber numberOfFiguresForEachNumber&#8221;<br />
    exit 1<br />
}</p>
<p>help(){<br />
    echo<br />
    echo &#8220;This script help the user in order to take multiple source images for the software X.&#8221;<br />
    echo<br />
    echo &#8220;1. Please make sure script Y is properly calibrated.&#8221;<br />
    echo &#8220;2. Press any key in order to take one shot, Ctrl+c to quit&#8221;<br />
    echo<br />
}</p>
<p>function zeropad {<br />
    expo=$((10 ** $2))<br />
    [ $1 -gt $expo ] &amp;formatd=$(($1 + $expo))<br />
    return=${formatd:1}<br />
}</p>
<p>if [ $# -ne $EXPECTED_ARGS ]<br />
then<br />
    usage<br />
    echo -n &#8220;Press any key to take shot!&#8221;<br />
else<br />
    COUNTER=$2<br />
    help<br />
    while [ 1 ]<br />
    do<br />
	read var_name<br />
	zeropad $COUNTER $3<br />
	imageName=$1$return.png<br />
	echo ./Y $imageName<br />
	COUNTER=$((COUNTER+1))<br />
	COUNTEROFSHOTS=$((COUNTEROFSHOTS+1))<br />
	echo -n $COUNTEROFSHOTS&#8221;.&#8221;$imageName.&#8221; done. Press any key to take shot!&#8221;<br />
    done<br />
fi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pbrisbin</title>
		<link>http://jonathanwagner.net/2007/04/zero-padding-in-bash/comment-page-1/#comment-1341</link>
		<dc:creator>pbrisbin</dc:creator>
		<pubDate>Wed, 28 Apr 2010 20:48:31 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanwagner.net/2007/04/zero-padding-in-bash/#comment-1341</guid>
		<description>Just a headsup, zero-padding was recently added to brace expansion (among other tricks). 

this is equivalent bash v4 code:

  for x in $(echo {01..32}); do mkdir $x; done</description>
		<content:encoded><![CDATA[<p>Just a headsup, zero-padding was recently added to brace expansion (among other tricks). </p>
<p>this is equivalent bash v4 code:</p>
<p>  for x in $(echo {01..32}); do mkdir $x; done</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>
