2 The **shuf** utility shuffles its input by outputting a random permutation of its input lines.
3 It is not a one-to-one reimplementation of the `shuf(1)` utility from GNU coreutils since it lacks some of its
8 * Compiled with security hardening flags.
9 * Static analysis integrated using clang's `scan-build` using checkers `alpha.security`, `alpha.core.CastSize`,
10 `alpha.core.CastToStruct`, `alpha.core.IdenticalExpr`, `alpha.core.PointerArithm`, `alpha.core.PointerSub`,
11 `alpha.core.SizeofPtr`, `alpha.core.TestAfterDivZero`, `alpha.unix`.
12 * Follows [FreeBSD coding style](https://www.freebsd.org/cgi/man.cgi?query=style&sektion=9).
14 * C99 compliant *and* may be built in an environment which provides POSIX.1-2001 system interfaces.
15 * Self-contained, no external dependencies.
16 * Easy to compile and uses POSIX make.
19 * Input lines are limited to `BUFSIZ` bytes in lenght.
20 * Does not implement the `-z` and `--random-source=file` flags present in GNU coreutils' `shuf(1)`.
21 * Uses the `rand()` function from `stdlib.h`.
24 The only dependency is a toolchain supporting the following flags:
27 CFLAGS = -std=c99 -O2 -Wall -Wextra -Wpedantic \
28 -Walloca -Wcast-qual -Wconversion -Wformat=2 -Wformat-security \
29 -Wnull-dereference -Wstack-protector -Wvla -Warray-bounds \
30 -Wbad-function-cast -Wconversion -Wshadow -Wstrict-overflow=4 -Wundef \
31 -Wstrict-prototypes -Wswitch-default -Wfloat-equal -Wimplicit-fallthrough \
32 -Wpointer-arith -Wswitch-enum \
34 -fstack-protector-strong -fPIE -fstack-clash-protection
36 LDFLAGS = -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-z,separate-code
39 Otherwise you can just remove the security flags and compile it with
41 CFLAGS = -std=c99 -O2 -Wall -Wextra -Wpedantic
45 or pass your own flags to make
47 make CC=gcc CFLAGS=... LDFLAGS=...
51 Clone this repository then
54 $ make PREFIX=/usr install
57 This will install the compiled binary under `PREFIX` (`/usr/bin`) in this case, if not specified `PREFIX` will default
58 to `/usr/local`. For staged installs, `DESTDIR` is also supported. As the binary does not have any dependency it does
59 not have to be installed before use.
63 shuf [-h] [-n count] [-o outfile] [-r] [file]
64 shuf [-h] -e [-n count] [-o outfile] [-r] [args ...]
65 shuf [-h] -i lo-hi [-n count] [-o outfile] [-r]
67 **shuf** has three modes of operation that control how the input is obtained. By default it takes input from standard
68 input. The input file can be omitted, in this case the program takes the input from the standard input until `EOF` or
69 `^D` is reached. If a file is a single dash (‘-’), **shuf** reads from standard input. The other two modes can be
70 switched by means of the `-e` and `-i` flags:
72 * `-e` treats each command-line operand as an input line.
73 * `-i` acts as input came from a file containing the numbers in the interval of unsigned integers [lo,hi] one on each
76 The three modes cannot be mixed together.
78 The other options are as follows:
80 * `-h` print usage information and exit.
81 * `-n count` output at most `count` lines.
82 * `-o outfile` output lines are printed on the specified file instead of standard output.
83 * `-r` repeat values. When this option is turned on, the output no longer contains permutations of the input lines,
84 instead each output line is randomly chosen from all the input lines. If `-n` is not also given, `shuf` prints randomly
85 chosen input lines indefinitely.
88 Output 5 random numbers in the range 0-2:
92 Flip a coin ten times:
94 $ shuf -e -n 10 -r Heads Tails
96 Select five numbers from 10 to 20:
100 Shuffle what is provided on standard input and write the output to out
106 Static analysis on the code base is done by using clang's static analyzer run through `scan-build.sh` which wraps the
107 `scan-build` utility. The checkers used are part of the
108 [Experimental Checkers](https://releases.llvm.org/12.0.0/tools/clang/docs/analyzer/checkers.html#alpha-checkers)
109 (aka *alpha* checkers):
112 * `alpha.core.CastSize`
113 * `alpha.core.CastToStruct`
114 * `alpha.core.IdenticalExpr`
115 * `alpha.core.PointerArithm`
116 * `alpha.core.PointerSub`
117 * `alpha.core.SizeofPtr`
118 * `alpha.core.TestAfterDivZero`
122 Send patches on the [mailing list](https://www.freelists.org/list/shuf-dev), report bugs using [git-bug](https://github.com/MichaelMure/git-bug/).
125 BSD 2-Clause FreeBSD License, see LICENSE.