bash single to double digit conversion

From thelinuxwiki
Jump to: navigation, search

method using printf...

for i in {1..12}; 
do
  i=`printf "%02d" $i`
  echo $i
done

output

01
02
03
04
05
06
07
08
09
10
11
12