Adding a zero to single digit variable

前端 未结 10 2092
星月不相逢
星月不相逢 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 06:19

    Here's what I did for a script where I'm asking for a day, range of days, regex, etc. with a default to the improved regexes shared by paxdiablo.

    for day in $days
        do if [ 1 -eq "${#day}"] ; then
            day="0$day"
        fi
    

    I just run through this at the beginning of my loop where I run a bunch of log analysis on the day in question, buried in directories with leading zeroes.

提交回复
热议问题