[colug-432] Bash script two digit names

jep200404 jep200404 at columbus.rr.com
Sun Jan 17 13:41:24 EST 2010


Tom Hanlon wrote: 

> I have a bash script that loops and create files.

> 01_1 for jan first
> 01_2 for Jan second.

> Problem is I would much rather have
> 
> 01_01 rather than 01_1
> 
> The loop goes from 1-31 and sets the variable for the loop counter.
> 
> Is there a built in utility to make a "one space" integer a "two  
> space" integer, or do I have to do that manually ?

i=1
while [ $i -le 31 ]; do
   printf "%02d\n" $i
   i=`expr $i + 1`
done

man 1 printf
man 3 printf



More information about the colug-432 mailing list