Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash sequence 00 01 ... 10

Tags:

bash

in bash, with

$ echo {1..10} 1 2 3 4 5 6 7 8 9 10 

I can get a numbers sequence, but in some case I need

01 02 03 ... 10 

how I can get this ?

and how I can get ?

001 002 ... 010 011 .. 100 
like image 837
JuanPablo Avatar asked Aug 09 '12 20:08

JuanPablo


People also ask

How do you sequence numbers in bash?

You can iterate the sequence of numbers in bash in two ways. One is by using the seq command, and another is by specifying the range in for loop. In the seq command, the sequence starts from one, the number increments by one in each step, and print each number in each line up to the upper limit by default.

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.

Is it true 1 or 0 bash?

There are no Booleans in Bash. However, we can define the shell variable having value as 0 (“ False “) or 1 (“ True “) as per our needs.

What is bash if [- N?

A null string in Bash can be declared by equalizing a variable to “”. Then we have an “if” statement followed by the “-n” flag, which returns true if a string is not null. We have used this flag to test our string “name,” which is null.


2 Answers

This will work in any shell on a machine that has coreutils installed (thanks commenters for correcting me):

seq -w 1 10 

and

seq -w 1 100 

Explanation:

  • the option -w will:

Equalize the widths of all numbers by padding with zeros as necessary.

  • seq [-w] [-f format] [-s string] [-t string] [first [incr]] last

prints a sequence of numbers, one per line (default), from first (default 1), to near last as possible, in increments of incr (default 1). When first is larger than last the default incr is -1

like image 50
favoretti Avatar answered Sep 28 '22 04:09

favoretti


use seq command with -f parameter, try:

seq -f "%02g" 0 10

results: 00 01 02 03 04 05 06 07 08 09 10

seq -f "%03g" 0 10

results: 000 001 002 003 004 005 006 007 008 009 010

like image 33
robin Avatar answered Sep 28 '22 05:09

robin