ENUM(1) | enum 1.1 | ENUM(1) |
NAME¶
enum - seq- and jot-like enumeratorSYNOPSIS¶
GENERAL¶
enum [ OPTIONS ] LEFT .. COUNTx STEP .. RIGHTSHORTCUTS¶
enum [ OPTIONS ] LEFT STEP RIGHTDESCRIPTION¶
enum enumerates values (numbers) from LEFT to RIGHT adding/subtracting STEP each time. If STEP is not provided a value is implied. No more than COUNT values are printed. Before printing, values are passed through a formatter. Please see OPTIONS for details on controlling the formatter or EXAMPLES for use cases.EXAMPLES¶
USE IN FOR-LOOPS¶
for i in $(enum -e 1 20); do touch file_${i} done
USE FOR RANDOM NUMBERS¶
number=$(enum --random 3 .. 10)
f() { min=$1; max=$2; echo $((RANDOM * (max - min + 1) / 32767 + min)); } number=$(f 3 10)
SHOWING AN ASCII TABLE¶
enum -f '[%3i] "%c"' 0 127
OPTIONS¶
RANDOM MODE¶
-r, --randomProduces random numbers (potentially with
duplicates) instead of monotonic sequences.
-i, --seed=NUMBER
Pass NUMBER as initializer to the
random number generator. By default, the RNG is initialized from the current
time and the process ID of the running instance of enum.
FORMATTING¶
-b, --dumb=TEXTOverrides the output format to TEXT
without interpolating placeholders. For instance, enum -b "foo %
10" 3x produces the string "foo % 10" three times.
-c, --characters
Overrides the output format to %c producing
characters. For example, enum -c 65 67 produces the letters
"A", "B" and "C".
-e, --equal-width
Equalize width by padding with leading zeroes.
NOTE: In the case of mixed negative and non-negative numbers (e.g. with
enum -e — -10 1), non-negative values will compensate for the
lack of a leading minus with an extra zero to be of equal width.
-f, --format=FORMAT
Overrides the default output format with
FORMAT. For details on allowed formats please see printf(3).
FORMAT is subject to processing of C escape sequences (e.g.
"\n" makes a newline). If FORMAT does not contain any
placeholders, enum will print FORMAT repeatedly. In contrast,
jot would have appended the number’s value instead. To make numbers
appear at the end with enum, adjust FORMAT appropriately.
-l, --line
Shortcut for "-s ' '" which
means having a space instead of a newline as separator.
-n, --omit-newline
Omits the terminating string (defaults to
newline) from output, i.e. it’s a shortcut to " -t
''".
-p, --precision=COUNT
Overrides automatic selection of precision to
print COUNT decimal places, e.g. "0.100" for COUNT =
3. By default, the number of digits to print is computed from the arguments
given and the (given or computed) step size.
-s, --separator=TEXT
Overrides the separator that is printed
between values. By default, values are separated by a newline. TEXT is
subject to processing of C escape sequences (e.g. "\n" makes a
newline).
-t, --terminator=TEXT
Overrides the terminator that is printed in
the very end. Default is a newline. TEXT is subject to processing of C
escape sequences (e.g. "\n" makes a newline).
-w, --word=FORMAT
Alias for --format, for compatibility with
jot. For GNU seq’s -w meaning --equal-width, see
-e.
-z, --zero, --null
Print null bytes as separator, not a
newline.
OTHER¶
-h, --helpOutputs usage information and exits with code
0 (success).
-V, --version
Displays version information and exits with
code 0 (success).
USAGE IN DETAIL¶
ARGUMENTS¶
The logic of enum's command line parameters is:•
LEFT, the value to start enumeration with
•
COUNT, the (maximum) number of values to produce
•
STEP, the gap from one value to another
•
RIGHT, the value to stop enumeration at (in some cases before)
VALID COMBINATIONS¶
With four arguments:•
enum LEFT .. COUNTx STEP ..
RIGHT
•
enum LEFT COUNTx RIGHT
•
enum LEFT .. COUNTx STEP
..
•
enum .. COUNTx STEP ..
RIGHT
•
enum LEFT .. COUNTx ..
RIGHT
•
enum LEFT .. STEP .. RIGHT
•
enum LEFT STEP RIGHT (for GNU seq
compatibility)
•
enum .. COUNTx STEP ..
•
enum .. COUNTx .. RIGHT
•
enum COUNTx .. RIGHT
•
enum .. STEP .. RIGHT
•
enum LEFT .. COUNTx ..
•
enum LEFT .. STEP ..
•
enum LEFT .. RIGHT
•
enum LEFT RIGHT (for GNU seq compatibility)
•
enum .. STEP ..
•
enum .. COUNTx ..
•
enum .. RIGHT
•
enum RIGHT (for GNU seq compatibility)
•
enum LEFT ..
•
enum COUNTx
DERIVATION OF DEFAULTS¶
AUTO-SELECTION OF PRECISION# enum 1 2 1 2 # enum 1 2.0 1.0 1.1 [..] 1.9 2.0
# enum 1 .. 3x .. 2 1.0 1.5 2.0
# enum -p 2 1 .. 3x .. 2 1.00 1.50 2.00
•
LEFT defaults to 1 (unless STEP and RIGHT are specified,
see DERIVATION OF LEFT below)
•
COUNT is infinity, unless it can be derived from the other three
values.
•
STEP defaults to 1, unless it can be derived.
•
RIGHT is +/-infinity, unless it can be derived from the other three
values.
# enum .. 3 1 2 3
# enum .. 4 .. 10 2 6 10
# enum .. 2x 4 .. 10 6 10
GENERATION OF VALUES¶
When a custom step is requested, values are produced as follows:value[0] = LEFT + 0 * STEP value[1] = LEFT + 1 * STEP .. value[i] = LEFT + i * STEP
value[0] = LEFT + (RIGHT - LEFT) / (COUNT - 1) * 0 value[1] = LEFT + (RIGHT - LEFT) / (COUNT - 1) * 1 .. value[i] = LEFT + (RIGHT - LEFT) / (COUNT - 1) * i
RANDOM MODE¶
Basically, random mode differs in these regards:•Produced values are random.
•Argument COUNT defaults to 1
(one).
•Argument LEFT (always!) defaults
to 1 (one).
•Argument RIGHT is required:
Random does not mix with infinity.
COUNT DEFAULTS TO 1 (ONE)¶
In random mode only one value is produced, by default:# enum 1 4 1 2 3 4 # enum -r 1 4 3
# enum -r 1 .. 3x .. 4 2 1 3
LEFT ALWAYS DEFAULTS TO 1 (ONE)¶
When you need increasing numbers up to a certain maximum (say 10), each separated by a certain step (say 4) you can let enum calculate the needed starting value for you:# enum .. 4 .. 10 2 6 10
# enum -r .. 5x 4 .. 10 1 1 9 1 5
RANDOM DOES NOT MIX WITH INFINITY¶
In general, enum supports running towards infinity:# enum 1 .. 2.0 .. 1.0 3.0 5.0 [..]
HISTORY¶
enum is a fusion of GNU seq and jot, feature-wise. At the core both tools print sequences of numbers. GNU seq has a clean interface but very limited functionality. jot on the other hand offers more advanced features, like producing random numbers, at the cost of a rather unfriendly interface.COMPARISON TO JOT¶
Using enum instead of jot offers two main advantages:•improved usability and
•uniform behavior across distributions
and operating systems.
•6 integers from 0 to 5 on FreeBSD and
OS X,
0 1 2 3 4 5
•100 integers from 0 to 99 on NetBSD,
and
0 1 2 [..] 97 98 99
•100 integers from 0 to 5 (with
consecutive duplicates) on DragonFlyBSD, MirOS BSD, and OpenBSD.
0 0 0 0 0 0 0 0 0 0 1 1 [..] 4 4 5 5 5 5 5 5 5 5 5 5
# jot -p 2 3 1.00 2.00 3.00 # enum -p 2 3 1.00 2.00 3.00
ADDITIONAL FEATURES¶
The extra features that enum offers over jot include:jot -r 3 1 10
enum -r 1 .. 3x .. 10 enum -r 1 3x 10
# enum -r 4 .. 100x 2 .. 10 | sort -u -n 4 6 8 10 # enum -r 4 .. 100x 3 .. 10 | sort -u -n 4 7 10
# jot -w %g%g 3 jot: too many conversions
# jot -w %g%g 3 jot: unknown or invalid format `%g%g'
# enum -f %g%g 3 11 22 33
# jot -w '%g\x41' 1 1\x41
# enum -w '%g\x41' 1 1A
# enum -w '%g \x25g' 1 1 %g
# enum -f 'sheep number %d' 2 | xargs -n 1 echo sheep number 1 sheep number 2
# enum --null -f 'sheep number %d' 2 | xargs --null -n 1 echo sheep number 1 sheep number 2
DIFFERENCES¶
HANDLING OF FORMATS WITHOUT PLACEHOLDERS# jot 3 -w test_ test_1 test_2 test_3
# enum -w test_ 3 test_ test_ test_
# enum -w test_%d 3 test_1 test_2 test_3
# jot 3 A 65 66 67
# jot 3 0 0 1 2
COMPARISON TO GNU SEQ¶
Basically, enum's usage is backwards-compatible to that of GNU seq.ADDITIONAL FEATURES¶
The extra features enum offers over GNU seq include:enum -r 4 .. 3x 2.0 .. 11
# seq 3 1 # enum 3 1 3 2 1
# seq -f %g%g 3 seq: format `%g%g' has too many % directives # enum -f %g%g 3 11 22 33
# seq -f '%g\x41' 1 1\x41
# seq -f '%g\x41' 3 1\x41 2\x41 3\x41
# seq -f '%g\x41' 1 1A 2A 3A
# seq -f '%g\x41' 1 1A3 2A3 3A3
# enum -f '%g\x41' 3 1A 2A 3A
# enum -f '%g \x25g' 1 1 %g
DIFFERENCES¶
GNU seq’s --equal-width shortcut -w conflicts with jot’s -w word. We chose to make -e the shortcut for --equal-width in enum, instead.THANKS¶
Elias Pipping, Andreas Gunschl, Justin B. Rye, David Prevot, Kamil Dudka, Michael BieniaAUTHORS¶
Jan Hauke Rahm <jhr@debian.org>RESOURCES¶
Main web site: https://fedorahosted.org/enum/SEE ALSO¶
jot(1), seq(1), printf(3)02/02/2012 | enum 1.1 |