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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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.