Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
How to zero-pad a number in bash?

printf is here to help :)

In order to zero-pad a number you need to use do like below:

your_number_var=1
output=$(printf "%02d" $your_number_var)
echo $output # 01

Here I have used %02d. the number 2 refers to numbers of padding and d refers to digit. So to zero-pad to 5 you can use %05d.
As simple as that.

#bash #printf #zeropad #zero-pad #zeropadding