The Sequence Expression is used to create a range of characters and integers by defining a start and endpoint. Usually, the Bash Sequence Expression is used with For Loops.

The syntax of Sequence Expression is:

{START..END[..INCREMENT]}

Here the start and end values are mandatory and can be either characters or integers. Next, the increment value is optional and if we use it then it must be separated from the End value with two dots. If we do not use an increment value then the default value would be 1. Let’s take an example of it.

  1. echo {0..3}
    

    Output

    0 1 2 3
  2. echo {a..e}
    

    Output

    a b c d e
  3. If the Start value is greater than the End value then there will be a decrement in the range.

    for i in {5..0}
    do 
     echo “No: $i”
    done 
    

    Output

    No: 5 No: 4 No: 3 No: 2 No: 1
  4. If we give an increment value in the range then.
    for i in {0..20..5}
    do 
       echo “No: $i”
    done
    

    Output

    No: 0 No: 5 No: 10 No: 15 No: 20
  5. We can also prefix and suffix the expression with other values.
    echo A{0..5}B
    

    Output

    A0B A1B A2B A3B A4B A5B
  6. You can also add a leading 0 in front of each integer to make them of the same length.
    for i in {00..5}
    do 
       echo “No: $i”
    done
    

    Output

    No: 00 No: 01 No: 02 No: 03 No: 04 No: 05
  7. We can also use seq Command to print a sequence.
    seq 1 5
    

    Output

    1 2 3 4 5
  8. echo “Even Numbers:” $(seq 0 2 10)
    

    Output

    Even Numbers: 0 2 4 6 8 10