seq

From Juneday education
Jump to: navigation, search


Description

seq - print a sequence of numbers.

On this page we only give you a short introduction with a few examples. We encourage you to read the manual (man seq).

Example output

Print the first 5 numbers

$ seq 1 5
1
2
3
4
5

Loop five times

Let's use seq to execute date five times and sleep 1 second in between

$ for nr in $(seq 1 5); do date; sleep 1 ; done
Tue Jan 24 10:48:47 CET 2017
Tue Jan 24 10:48:48 CET 2017
Tue Jan 24 10:48:49 CET 2017
Tue Jan 24 10:48:50 CET 2017
Tue Jan 24 10:48:51 CET 2017

Calculate the product of the 5 first numbers

$ PROD=1; for nr in $(seq 1 5); do PROD=$(( $PROD * $nr )); done; echo "Product: $PROD"