Adding a zero to single digit variable

前端 未结 10 2089
星月不相逢
星月不相逢 2021-01-30 05:31

Trying to add a zero before the varaible if it\'s less than 10 and create said directory. I can\'t seem to get the zero to add correctly. Keeps resulting in making 02.1.20

10条回答
  •  借酒劲吻你
    2021-01-30 05:58

    You can use

    $(printf %02d $i)
    

    To generate the numbers with the format you want.

    for i in $(seq 0 1 31)
    do
        mkdir $path/02.$(printf %02d $i).2011
    done
    

提交回复
热议问题