Difference between revisions of "Seq"

From Linuxintro
imported>ThorstenStaerk
 
(One intermediate revision by one other user not shown)
Line 24: Line 24:
  
 
= See also =
 
= See also =
* [[bAsh scripting tutorial]]
+
* [[bash scripting tutorial]]
 +
* [http://linux.die.net/man/1/seq seq man page]

Latest revision as of 15:30, 30 June 2014

seq is a command to show a sequence of numbers. For example the sequence from 1 to 5 can be shown like this:

# seq 1 5
1
2
3
4
5

seq is great to be used in for loops like this:

# for i in $(seq 1 8); do echo "the square of $i is $(($i*$i))"; done
the square of 1 is 1
the square of 2 is 4
the square of 3 is 9
the square of 4 is 16
the square of 5 is 25
the square of 6 is 36
the square of 7 is 49
the square of 8 is 64

To show all ascii characters you can use the following command:

for l in $(seq 0 1 7); do for i in $(seq 0 1 7); do for n in $(seq 0 1 7); do \
echo -en "\0${l}${i}${n}  "; done; done; done

See also