aboutsummaryrefslogtreecommitdiff
path: root/bin/rndf
blob: fa11e68eeb8673b97d2f379b1c084128060c1cd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
# Choose a random file from a given directory. Ignores dot files.
dir=${1:-.}
set -- "$dir"/*
if ! [ -e "$1" ] ; then
    printf >&2 'rndf: No files found in %s\n' "$dir"
    exit 1
fi
argi=$(rndi 1 "$#") || exit
shift "$((argi-1))"
printf '%s\n' "$1"