aboutsummaryrefslogtreecommitdiff
path: root/bin/rndl
blob: 978fc19457240b562f8b1d182b0fcb260c0d7eaf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh
# Print a random line from input
td=
cleanup() {
    rm -fr -- "$td"
}
for sig in EXIT HUP INT TERM ; do
    trap cleanup "$sig"
done
if [ "$#" -eq 0 ] ; then
    td=$(mktd rndl) || exit
    set -- "$td"/stdin
    cat >"$td"/stdin
fi
lc=$(sed -- '$=;d' "$@") || exit
seed=$(rnds)
ri=$(rndi 1 "$lc" "$seed") || exit
sed -- "$ri"'!d' "$@"