Bash Script to Generate a List of Numbers

A simple example of a bash script one-liner that generates a list of numbers and outputs the list to a file.

for i in $(seq 1 100); do echo $i >> sequence.txt; done

This script takes advantage of the Linux seq command, which generates numbers based on the input specified. We can specify the starting and ending values, as well a step increment.

We can see many more details in the man page for seq:

In this case, we created a list of numbers from 1 to 100 using ‘seq 1 100’.

The seq command is wrapped in a for statement, which loops through the sequence, echoes it, and then copies each line to the ‘sequence.txt’ file.