Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

As an example, here is the code:

until [ $s -eq 60 ] 
    let "s += 1"
    echo $s

$s will be 1, 2, 3 etc, but not 01, 02, 03 etc. How can I avoid this deletion of 0? So, I need $s to be 01-09, then 10, 11, etc.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Add the zeros when you print it.

#!/usr/bin/env bash
until ((++s == 60 )); do
    printf '%02d\n' "$s"

Numbers with leading zeros will be treated as octal, so values like 08 and 09 will fail. Therefore it's best to operate on the numbers without the leading zeros and only add the leading zeros when you need to print it.

Also see

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.