aboutsummaryrefslogtreecommitdiff
path: root/bin/rndf
blob: 06e15fbe03329a2f81aacb315348e7b2aeeb6599 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
# Choose a random file from a given directory using rnda(1); ignores dot files

# Directory is first argument; defaults to current directory
dir=${1:-.}

# Set the positional parameters to all the non-dotfiles in that directory
set -- "$dir"/*

# Check for an unexpanded glob (empty directory)
if ! [ -e "$1" ] ; then
    printf >&2 'rndf: No files found in %s\n' "$dir"
    exit 1
fi

# Print a random argument from the current positional parameters
rnda "$@"