Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:05:10+00:00 2026-05-28T00:05:10+00:00

I need to loop some values, for i in $(seq $first $last) do does

  • 0

I need to loop some values,

for i in $(seq $first $last)
do
    does something here
done

For $first and $last, I need it to be of fixed length 5. So if the input is 1, I need to add zeros in front such that it becomes 00001. It loops till 99999 for example, but the length has to be 5.

E.g.: 00002, 00042, 00212, 12312 and so forth.

Any idea on how I can do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:05:11+00:00Added an answer on May 28, 2026 at 12:05 am

    In your specific case though it’s probably easiest to use the -f flag to seq to get it to format the numbers as it outputs the list. For example:

    for i in $(seq -f "%05g" 10 15)
    do
      echo $i
    done
    

    will produce the following output:

    00010
    00011
    00012
    00013
    00014
    00015
    

    More generally, bash has printf as a built-in so you can pad output with zeroes as follows:

    $ i=99
    $ printf "%05d\n" $i
    00099
    

    You can use the -v flag to store the output in another variable:

    $ i=99
    $ printf -v j "%05d" $i
    $ echo $j
    00099
    

    Notice that printf supports a slightly different format to seq so you need to use %05d instead of %05g.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with an array and a foreach loop, I have an
I need to write some code that would loop though all rows of a
I need to loop through a set of 2-dimensional array of hidden input fields
I have some troubles to find the right loop to check if some values
i need some help regarding adding values into an array for example long[] s
I need to return multiple STRING values from my backgroundworker in each loop, so
Im trying to add some values up but some of the values have a
I need to compare some Rails (2.3.11) model attribute values before and after a
i need some help writing a for-loop please but i can't get it. i
I need to loop through all the matches in say the following string: <a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.