[PLUG] bash decimal interpretation
Jeme A Brelin
jeme at brelin.net
Wed Dec 3 03:40:03 UTC 2003
On Wed, 3 Dec 2003, Chris Jantzen wrote:
> On Wed, Dec 03, 2003 at 02:54:40AM -0800, Jeme A Brelin wrote:
> >
> > On Wed, 3 Dec 2003, Chris Jantzen wrote:
> > > It'll just overflow the width. "5" becomes "05", but "123" becomes
> > > "123". It does, however, beg the question of "why pad if you don't know
> > > how wide you want it?"
> >
> > Well, it's that I want it all the same length. So I have to figure out
> > the length of the longest one and pad to that. -w does this for me.
> >
> > It's not that I don't know how long I want it, I just don't know yet.
>
> Well, you're issuing "seq 1 bar", so why not do:
>
> export WIDTH=`echo -n $bar | wc -c`
> for a in `seq 1 $bar`; do printf "%0${WIDTH}d\n" $a; done
>
> Getting uglier by the minute, but it works.
Um, I'm really not trying to get you to do my work here... but I have one
more problem to which I don't see the (surely) obvious answer.
Do I just backtick that to get it into a variable I can actually use?
b=`printf "%0${WIDTH}d" $a`
That's the best way?
J.
--
-----------------
Jeme A Brelin
jeme at brelin.net
-----------------
[cc] counter-copyright
http://www.openlaw.org
More information about the PLUG
mailing list