Bash Wiki
Posts (Latest 30 updated) :
Read all
Contents:
  1. [Linux] Bash seq Uso equivalente: Generate a sequence of numbers
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
    5. Tips

[Linux] Bash seq Uso equivalente: Generate a sequence of numbers

Overview

The seq command in Bash is used to generate a sequence of numbers. It allows users to create a list of numbers in a specified range, which can be useful for scripting and automation tasks.

Usage

The basic syntax of the seq command is as follows:

seq [options] [arguments]

Common Options

  • -f FORMAT: Specifies a format for the output numbers.
  • -s STRING: Sets a custom separator between the numbers (default is a newline).
  • -w: Pads the numbers with leading zeros to make them the same width.

Common Examples

  1. Basic Sequence Generation Generate numbers from 1 to 10:
    seq 1 10
    
  2. Custom Step Value Generate numbers from 1 to 10 with a step of 2:
    seq 1 2 10
    
  3. Formatted Output Generate numbers from 1 to 5 with a specific format:
    seq -f "Number: %g" 1 5
    
  4. Using a Custom Separator Generate numbers from 1 to 5 separated by commas:
    seq -s "," 1 5
    
  5. Zero-Padded Numbers Generate numbers from 1 to 10 with leading zeros:
    seq -w 1 10
    

Tips

  • Use seq in combination with other commands in a pipeline to automate tasks efficiently.
  • When generating large sequences, consider performance implications and the potential for large outputs.
  • Remember that seq can be a handy tool for creating lists for loops in scripts.