bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to control the width of a number?


From: Peng Yu
Subject: Re: How to control the width of a number?
Date: Tue, 4 May 2010 10:46:44 -0500

On Tue, May 4, 2010 at 10:28 AM, Dennis Williamson
<dennistwilliamson@gmail.com> wrote:
> for i in {28..55}
> # or: for ((i=28; i<=55; i++))
> do
>  (( page = 148 - ( i - 28 ) * 2 ))
>  printf '$d $03d\n' $i $page
> done

I assume that you mean '%d %03d'.

> This eliminates external calls to bc and seq in addition to zero-padding 
> $page.

It is good to know this trick.

> On Tue, May 4, 2010 at 8:05 AM, Peng Yu <pengyu.ut@gmail.com> wrote:
>> Hi,
>>
>> I want $page has three digits. If it is less than 100, prefix it with
>> 0. Is there an easy way to do so in bash?
>>
>> for i in `seq 28 55`;
>> do
>>  page=`echo '148-('$i'-28)*2'|bc`
>>  echo $i $page
>> done
>>
>> --
>> Regards,
>> Peng
>>
>>
>>
>



-- 
Regards,
Peng




reply via email to

[Prev in Thread] Current Thread [Next in Thread]