Skip to documentation
DocumentationAll documentsEnglish

LOOP(1)

NAME

loop - generate numeric or character sequences for shell loops

On this page

SYNOPSIS

loop [-c] start finish [incr]

DESCRIPTION

loop outputs a sequence of values between start and finish (inclusive), one value per line on standard output. It is intended for driving counted loops in shell scripts.

The values are integers, real numbers, or characters. By default loop prints integers; if any of start, finish, or incr contains a decimal point or otherwise parses only as a floating-point number, the sequence is generated and printed as real numbers (using %g formatting). The -c option selects character sequences instead.

The default incr is 1 when start is less than finish and -1 when start is greater than finish, so the sequence always runs toward finish. An incr of zero is an error. No attempt is made to detect or prevent infinite loops.

For integer sequences, loop preserves zero padding: if start, finish, or incr is written with leading zeros, the output is left-padded with zeros to the width of the widest such argument (for example, 008 through 010).

OPTIONS

-c

Generate a character sequence. start and finish are taken as single characters and the output steps through the character codes between them. An optional incr may be supplied but must be an integer.

EXAMPLES

Example 1. Count from 10 to 30 in steps of 5
loop 10 30 5

Prints 10, 15, 20, 25, 30 on successive lines.

Example 2. Drive a render loop over zero-padded frame numbers
for frame in $(loop 001 100) ; do
    rt -o frame${frame}.pix -F /dev/null model.g component
done

Renders 100 frames, naming the outputs frame001.pix through frame100.pix. Because the bounds are written with leading zeros, loop zero-pads every value to three digits so the file names sort correctly.

Example 3. Generate a descending real-number ramp
loop 1.6 0.1 -0.5

Prints 1.6, 1.1, 0.6, 0.1; the decimal point selects floating-point mode and the negative incr steps downward.

Example 4. Step through an alphabetical range
loop -c a e

Prints the characters a through e, one per line.

SEE ALSO

brlcad(1), rt(1), gencolor(1)

AUTHOR

BRL-CAD Team

This software is Copyright (c) 1989-2026 by the United States Government as represented by U.S. Army Research Laboratory.

BUG REPORTS

Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org