seq
The seq
command in Unix-like operating systems generates sequences of numbers, either in increasing or decreasing order. It's useful in shell scripting for iterating over a range of numbers or generating lists.
Basic Syntax
options: Optional flags that modify the behavior of the
seq
command.start: The starting number of the sequence (default is 1).
increment: The increment between numbers (default is 1).
end: The ending number of the sequence.
Examples
Generating a Sequence of Numbers
Output:
Specifying Start and End
Output:
Generating Numbers with Increment
Output:
Generating a Sequence in Reverse Order
Output:
Practical Use Cases
Looping with for
and seq
for
and seq
Creating Directories
File Operations
Advanced Examples
Using seq
in a for
Loop
seq
in a for
LoopGenerating a Fixed-Length Sequence
Output:
Conclusion
The seq
command is a handy tool in shell scripting for generating sequences of numbers efficiently. It simplifies tasks such as looping through ranges of numbers, creating directories or files in batches, and performing mathematical operations in scripts. By leveraging seq
, you can make your shell scripts more dynamic and versatile.
Last updated