count - generate integer sequences


count [ from ] to [ by [ fmt ] ]
count [ -f fmt ] range


count is a simple utility for generating sequences of integers. For example,

	count 10
counts to 10, printing the integers from 1 to 10 on the standard output, one integer per line. count is most useful in shell scripts--for example, to code a Bourne shell loop which iterates the variable I from 1 to 10, you could write
	for I in `count 10`; do <commands>; done

Invoking count with two arguments indicates a start and end for the sequence; for example,

	count 10 20
counts from 10 to 20. A third argument indicates an increment:
	count 10 30 5
counts from 10 to 30 by 5.

An alternate invocation form allows generation of noncontiguous sequences, using a concise input syntax. The syntax is borrowed from the -o switch of troff(1) (and as used by line, q.v.). Hyphens indicate ranges, and commas separate individual numbers or ranges. For example,

	count 1,3,5-9
would print the numbers 1, 3, and 5 through 9.

It is also possible to modify the output format. By default, count prints decimal integers, but it is possible to specify an arbitrary format specifier, in the style of printf(3). The format is specified either as a fourth argument in the first invocation style, or by using the -f option. For example,

	count 1 20 1 %o
would count from 1 to 20 in octal (base 8). (Note that in this invocation form, an explicit increment must be specified.) Any integral printf(3) format specifier may be used--for example (and demonstrating the use of the -f flag),
	count -f %c 97 102
would print the letters a through f (assuming an ASCII machine). Up to five format specifiers may be used, all of which will expand to the same value on each line printed. For example,
	count -f "%c has code %d" 65,69,73,79,85
would (again, assuming an ASCII machine) print the five capital vowels and their character codes.


The range is limited to that of the C ``int'' type.



See for possible updates.


Steve Summit,