Bash - Sequence

Bash Liste Des Attaques Ovh

About

A sequence expression is a construct that creates sequence of numbers or characters.

Syntax

It's a brace expansion and takes the form

{x..y}

where x and y are either:

A correctly-formed brace expansion must contain:

  • unquoted opening
  • closing braces,
  • and at least one unquoted comma or a valid sequence expression.

Any incorrectly formed brace expansion is left unchanged.

A { or , may be quoted with a backslash to prevent its being considered part of a brace expression.

To avoid conflicts with parameter expansion, the string ${ is not considered eligible for brace expansion.

Management

Creation

Integers

When integers are supplied, the expression expands to each number between x and y, inclusive.

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

Character

When characters are supplied, the expression expands to each character lexicographically between x and y, inclusive. Note that both x and y must be of the same type.

echo {a..f}
a b c d e f

Loop

Integer For

Bash - For Statement

  • With hard-coded limit
for i in {1..10}; 
do 
    echo $i; 
done 
# or
for (( n=1; n<=10; n++ ))  
do  
    echo "$n"
done  
  • With variable limit
end=10
for i in $(seq 1 $end); 
do 
    echo $i; 
done

Integer While

Bash - While

count=0  
while [ $count -le 10 ]  
do  
    echo "$count"
    count=$(( $count + 1 ))
done  

Character For

for letter in {a..f}  
do  
    echo "$letter"
done 
  • A array
for color in Blue Red
do  
    echo "$color"
done 





Discover More
Bash Liste Des Attaques Ovh
Bash - Brace Expansion {} (Data Generation)

Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to pathname expansion, but the filenames generated need not exist. Patterns to be brace expanded...
Bash Liste Des Attaques Ovh
Bash - While

This article is dedicated to the while syntax in Bash. where: : is the no-op command; its exit status is always 0 The command: lists the file with the ls executable (ls -l) pipe the...



Share this page:
Follow us:
Task Runner