Adding a zero to single digit variable

前端 未结 10 2193
星月不相逢
星月不相逢 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:55

    I created this simple utility to perform this, Good Luck , hope this helps stack'ers!!

    for i in {1..24}
    do
    charcount=`echo $i|wc -m`
    count=`expr $charcount - 1`
    if [ $count -lt 2 ];
    then
    i="0`echo $i`"
    fi
    echo "$i"
    done
    

提交回复
热议问题