How to zero-pad a number in
In order to zero-pad a number you need to use do like below:
Here I have used
As simple as that.
#bash #printf #zeropad #zero-pad #zeropadding
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